ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-08-24 12:35:46
Exec Total Coverage
Lines: 3098 8724 35.5%
Functions: 83 303 27.4%
Branches: 2684 7675 35.0%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "base/md5.h"
33 #include "hero_tiles.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include "iter.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern uint8_t ViewLayer3BG, ViewLayer2BG;
59 extern int32_t LayerDitherBG, LayerDitherSz;
60 extern bool NoHighlightLayer0;
61
62 using std::string;
63 using std::pair;
64
65 #define COLOR_SOLID vc(4)
66 #define COLOR_SLOPE vc(13)
67 #define COLOR_LADDER vc(6)
68 //#define COLOR_EFFECT vc(10)
69
70 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
71 extern char msgbuf[MSG_NEW_SIZE*8];
72
73 extern string zScript;
74
75 12 zmap Map;
76 int32_t prv_mode=0;
77
78 bool save_warn=true;
79
80 int32_t COMBOPOS(int32_t x, int32_t y)
81 {
82 return (((y) & 0xF0) + ((x) >> 4));
83 }
84 int32_t COMBOPOS_B(int32_t x, int32_t y)
85 {
86 if(unsigned(x) >= 256 || unsigned(y) >= 176)
87 return -1;
88 return COMBOPOS(x,y);
89 }
90 int32_t COMBOX(int32_t pos)
91 {
92 return ((pos) % 16 * 16);
93 }
94 int32_t COMBOY(int32_t pos)
95 {
96 return ((pos) & 0xF0);
97 }
98
99 void reset_dmap(int32_t index)
100 {
101 bound(index,0,MAXDMAPS-1);
102 DMaps[index].clear();
103 DMaps[index].title = "";
104 sprintf(DMaps[index].intro, " ");
105 }
106
107 void reset_dmaps()
108 {
109 for(int32_t i=0; i<MAXDMAPS; i++)
110 reset_dmap(i);
111 }
112
113 void truncate_dmap_title(std::string& title)
114 {
115 title.resize(21, ' ');
116 }
117
118 mapscr* zmap::get_prvscr()
119 {
120 return &prvscr;
121 }
122
123
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 23 times.
138 zmap::zmap()
124 {
125 23 can_paste=false;
126 23 prv_cmbcycle=0;
127 23 prv_advance=0;
128 23 prv_freeze=0;
129 23 copyffc=-1;
130
131 23 memset(scrpos, 0, sizeof(scrpos));
132 23 memset(scrview, 0, sizeof(scrview));
133 23 screens=NULL;
134 23 prv_time=0;
135 23 prv_scr=0;
136 23 prv_map=0;
137 23 copyscr=0;
138 23 cursor={};
139 copymap=0;
140 layer_target_map = 0;
141 layer_target_scr = 0;
142 layer_target_multiple = 0;
143 }
144
145 11 void zmap::clear()
146 {
147
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
148 11 }
149 void zmap::force_refr_pointer()
150 {
151 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
152 screens = nullptr;
153 else screens = &TheMaps[cursor.map*MAPSCRS];
154 }
155 bool zmap::CanUndo()
156 {
157 return undo_stack.size() > 0;
158 }
159 bool zmap::CanRedo()
160 {
161 return redo_stack.size() > 0;
162 }
163 bool zmap::CanPaste()
164 {
165 return can_paste;
166 }
167 int32_t zmap::CopyScr()
168 {
169 return (copymap<<8)+copyscr;
170 }
171 int32_t zmap::getCopyFFC()
172 {
173 return copyffc;
174 }
175 set_ffc_command::data_t zmap::getCopyFFCData()
176 {
177 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
178 }
179 67 int32_t zmap::getMapCount()
180 {
181 67 return map_count;
182 }
183 int32_t zmap::getLayerTargetMap()
184 {
185 return layer_target_map;
186 }
187 int32_t zmap::getLayerTargetScr()
188 {
189 return layer_target_scr;
190 }
191 int32_t zmap::getLayerTargetMultiple()
192 {
193 return layer_target_multiple;
194 }
195 bool zmap::isDungeon(int32_t scr)
196 {
197 for(int32_t i=0; i<4; i++)
198 {
199 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
200 {
201 return false;
202 }
203 }
204
205 return true;
206 }
207
208 bool zmap::clearall(bool validate)
209 {
210 Color=0;
211 char tbuf[10];
212
213 if((header.templatepath[0]!=0)&&validate)
214 {
215 if(!valid_zqt(header.templatepath))
216 {
217 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
218 return false;
219 }
220 }
221
222 for(int32_t i=0; i<map_count; i++)
223 {
224 setCurrMap(i);
225 sprintf(tbuf, "%d", i);
226 clearmap(true);
227 }
228
229 setCurrMap(0);
230 return true;
231 }
232
233 bool zmap::reset_templates(bool validate)
234 {
235 //why are we doing this?
236 if(colordata==NULL)
237 {
238 return false;
239 }
240
241 //int32_t ret;
242 word version, build, dummy, sversion=0;
243 byte dummyc;
244 word dummyw;
245 //int32_t section_size;
246 word temp_map_count;
247 mapscr temp_mapscr;
248 PACKFILE *f=NULL;
249
250 // setPackfilePassword(datapwd);
251 f=open_quest_template(&header, "modules/classic/default.qst", validate);
252 get_version_and_build(f, &version, &build);
253
254 if(!find_section(f, ID_MAPS))
255 {
256 // setPackfilePassword(NULL);
257 return false;
258 }
259
260 //section version info
261 if(!p_igetw(&sversion,f))
262 {
263 return false;
264 }
265
266 if(!p_igetw(&dummy,f))
267 {
268 return false;
269 }
270
271 //section size
272 dword dummy_size;
273 if(!p_igetl(&dummy_size,f))
274 {
275 return false;
276 }
277
278 //finally... section data
279 if(!p_igetw(&temp_map_count,f))
280 {
281 return false;
282 }
283
284 if(version>12)
285 {
286 if(!p_getc(&dummyc,f))
287 return qe_invalid;
288
289 if(!p_getc(&dummyc,f))
290 return qe_invalid;
291
292 if(!p_igetw(&dummyw,f))
293 return qe_invalid;
294
295 if(!p_igetw(&dummyw,f))
296 return qe_invalid;
297
298 if(!p_igetw(&dummyw,f))
299 return qe_invalid;
300
301 if(!p_igetw(&dummyw,f))
302 return qe_invalid;
303
304 if(!p_igetw(&dummyw,f))
305 return qe_invalid;
306
307 if(!p_igetw(&dummyw,f))
308 return qe_invalid;
309
310 if(!p_igetw(&dummyw,f))
311 return qe_invalid;
312
313 if(!p_igetw(&dummyw,f))
314 return qe_invalid;
315
316 if(!p_igetw(&dummyw,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_getc(&dummyc,f))
323 return qe_invalid;
324
325 if(!p_getc(&dummyc,f))
326 return qe_invalid;
327 }
328
329 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
330 {
331 readmapscreen(f, &header, &temp_mapscr, sversion);
332 }
333
334 readmapscreen(f, &header, &TheMaps[128], sversion);
335 readmapscreen(f, &header, &TheMaps[129], sversion);
336
337 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
338 {
339 readmapscreen(f, &header, &temp_mapscr, sversion);
340 }
341
342 if(version>12)
343 {
344 if(!p_getc(&dummyc,f))
345 return qe_invalid;
346
347 if(!p_getc(&dummyc,f))
348 return qe_invalid;
349
350 if(!p_igetw(&dummyw,f))
351 return qe_invalid;
352
353 if(!p_igetw(&dummyw,f))
354 return qe_invalid;
355
356 if(!p_igetw(&dummyw,f))
357 return qe_invalid;
358
359 if(!p_igetw(&dummyw,f))
360 return qe_invalid;
361
362 if(!p_igetw(&dummyw,f))
363 return qe_invalid;
364
365 if(!p_igetw(&dummyw,f))
366 return qe_invalid;
367
368 if(!p_igetw(&dummyw,f))
369 return qe_invalid;
370
371 if(!p_igetw(&dummyw,f))
372 return qe_invalid;
373
374 if(!p_igetw(&dummyw,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_getc(&dummyc,f))
381 return qe_invalid;
382
383 if(!p_getc(&dummyc,f))
384 return qe_invalid;
385 }
386
387 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
388 {
389 readmapscreen(f, &header, &temp_mapscr, sversion);
390 }
391
392 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
393 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
394
395 pack_fclose(f);
396 clear_quest_tmpfile();
397
398 return true;
399 }
400
401 bool zmap::clearmap(bool newquest)
402 {
403 if(cursor.map<map_count)
404 {
405 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
406 {
407 clearscr(i);
408 }
409
410 setCurrScr(0);
411
412 if(newquest)
413 {
414 if(!reset_templates(false))
415 {
416 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
417 }
418 }
419 }
420
421 return true;
422 }
423
424 MapCursor zmap::getCursor() const
425 {
426 return cursor;
427 }
428
429 void zmap::setCursor(MapCursor new_cursor)
430 {
431 if (cursor == new_cursor)
432 return;
433
434 optional<int> oldcolor;
435 if (screens)
436 oldcolor = getcolor();
437
438 cursor = new_cursor;
439
440 int newcolor = getcolor();
441 loadlvlpal(newcolor);
442 if (!oldcolor || *oldcolor != newcolor)
443 rebuild_trans_table();
444
445 reset_combo_animations2();
446 mmap_mark_dirty();
447 regions_mark_dirty();
448 refresh(rALL);
449 }
450
451 bool zmap::isValidPosition(ComboPosition pos) const
452 {
453 return pos.is_valid(cursor);
454 }
455
456 int zmap::getScreenForPosition(ComboPosition pos) const
457 {
458 return cursor.viewscr + pos.screen_offset();
459 }
460
461 mapscr* zmap::CurrScr()
462 {
463 return screens+cursor.screen;
464 }
465 mapscr* zmap::Scr(int32_t scr)
466 {
467 return screens+scr;
468 }
469 mapscr* zmap::Scr(ComboPosition pos)
470 {
471 if (!pos.is_valid(cursor))
472 return nullptr;
473
474 int screen_offset = pos.screen_offset();
475 int screen = cursor.viewscr + screen_offset;
476 return AbsoluteScr(cursor.map, screen);
477 }
478 mapscr* zmap::Scr(ComboPosition pos, int layer)
479 {
480 int map = cursor.map;
481 int screen = cursor.viewscr + pos.screen_offset();
482 if (layer)
483 {
484 mapscr* scr = Map.AbsoluteScr(map, screen);
485 map = scr->layermap[CurrentLayer-1]-1;
486 screen = scr->layerscreen[CurrentLayer-1];
487 }
488
489 return AbsoluteScr(map, screen);
490 }
491 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
492 {
493 mapscr* scr = Scr(pos, layer);
494 if (scr && !(scr->valid&mVALID))
495 {
496 scr->valid |= mVALID;
497 setcolor(Color, scr);
498 }
499 return scr;
500 }
501 mapscr* zmap::AbsoluteScr(int32_t scr)
502 {
503 if(unsigned(scr) >= MAPSCRS*getMapCount())
504 return nullptr;
505 return &TheMaps[scr];
506 }
507 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
508 {
509 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
510 return nullptr;
511 return AbsoluteScr((map*MAPSCRS)+scr);
512 }
513 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
514 {
515 mapscr* scr = AbsoluteScr(map, screen);
516 if (scr && !(scr->valid&mVALID))
517 {
518 scr->valid |= mVALID;
519 setcolor(Color, scr);
520 }
521 return scr;
522 }
523 void zmap::set_prvscr(int32_t map, int32_t scr)
524 {
525 prvscr = *get_canonical_scr(map, scr);
526
527 for(int32_t i=0; i<6; i++)
528 {
529 if(prvscr.layermap[i]>0)
530 {
531 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
532 }
533 else
534 prvlayers[i].valid = 0;
535 }
536
537 prv_map=map;
538 prv_scr=scr;
539 }
540 92 int32_t zmap::getCurrMap()
541 {
542 92 return cursor.map;
543 }
544 22 void zmap::regions_mark_dirty()
545 {
546 22 regions_dirty = true;
547 22 }
548 void zmap::regions_refresh()
549 {
550 if (!regions_dirty)
551 return;
552
553 regions_dirty = false;
554 region_descriptions.clear();
555
556 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
557 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
558 region_descriptions.clear();
559 }
560 const std::vector<region_description>& zmap::get_region_descriptions()
561 {
562 regions_refresh();
563 return region_descriptions;
564 }
565 bool zmap::is_region(int screen)
566 {
567 if (screen < 0 || screen >= 128)
568 return false;
569
570 regions_refresh();
571 return current_map_region_ids[screen];
572 }
573 bool zmap::isDark(int scr)
574 {
575 return (screens[scr].flags&fDARK)!=0;
576 }
577 bool zmap::isValid(int32_t scr)
578 {
579 return (screens[scr].valid&mVALID)!=0;
580 }
581 bool zmap::isValid(int32_t map, int32_t scr)
582 {
583 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
584 }
585
586 11 void zmap::setCurrMap(int32_t index)
587 {
588 11 optional<int> oldcolor;
589
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(screens)
590 oldcolor = getcolor();
591 11 scrpos[cursor.map] = cursor.screen;
592 11 scrview[cursor.map] = cursor.viewscr;
593 11 cursor.map = bound(index,0,map_count);
594 11 screens = &TheMaps[cursor.map*MAPSCRS];
595
596 11 cursor.viewscr = scrview[cursor.map];
597 11 cursor.setScreen(scrpos[cursor.map]);
598
599 11 int newcolor = getcolor();
600 11 loadlvlpal(newcolor);
601
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if(!oldcolor || *oldcolor != newcolor)
602 11 rebuild_trans_table();
603
604 11 reset_combo_animations2();
605 11 mmap_mark_dirty();
606 11 regions_mark_dirty();
607 11 }
608
609 20 int32_t zmap::getCurrScr()
610 {
611 20 return cursor.screen;
612 }
613 11 void zmap::setCurrScr(int32_t scr)
614 {
615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (scr == cursor.screen)
616 return;
617
618 11 int32_t oldcolor=getcolor();
619 11 cursor.setScreen(scr);
620
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!(screens[cursor.screen].valid&mVALID))
621 {
622 oldcolor=-1;
623 }
624
625 11 int32_t newcolor=getcolor();
626 11 loadlvlpal(newcolor);
627
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 if (newcolor!=oldcolor)
628 {
629 10 rebuild_trans_table();
630 10 }
631
632 11 reset_combo_animations2();
633 11 setlayertarget();
634 11 mmap_mark_dirty();
635 11 regions_mark_dirty();
636 11 }
637
638 int32_t zmap::getViewScr()
639 {
640 return cursor.viewscr;
641 }
642
643 11 void zmap::setViewSize(int32_t size)
644 {
645 11 cursor.setSize(size);
646 11 }
647
648 8 int32_t zmap::getViewSize()
649 {
650 8 return cursor.size;
651 }
652
653 11 void zmap::setlayertarget()
654 {
655 11 layer_target_map = 0;
656 11 layer_target_multiple = 0;
657
658
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
659 {
660
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
661 {
662 7616 int32_t i=(m*MAPSCRS+s);
663 7616 mapscr *ts=&TheMaps[i];
664
665 // Search through each layer
666
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
667 {
668
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 45679 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
669 {
670 if(layer_target_map > 0)
671 {
672 layer_target_multiple += 1;
673 continue;
674 }
675
676 layer_target_map = m+1;
677 layer_target_scr = s;
678 }
679 45696 }
680 7616 }
681 56 }
682 11 }
683
684 void zmap::setcolor(int color, mapscr* scr)
685 {
686 if (!scr) scr = CurrScr();
687 scr->valid |= mVALID;
688 scr->color = color;
689
690 if(Color!=color)
691 {
692 Color = color;
693 loadlvlpal(color);
694 rebuild_trans_table();
695 }
696
697 mmap_mark_dirty();
698 }
699
700 33 int32_t zmap::getcolor()
701 {
702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(prv_mode)
703 {
704 return prvscr.color;
705 }
706
707 33 return screens[cursor.screen].color;
708 33 }
709
710 void zmap::resetflags()
711 {
712 byte *di=&(screens[cursor.screen].valid);
713
714 for(int32_t i=1; i<48; i++)
715 {
716 *(di+i)=0;
717 }
718 }
719
720 word zmap::tcmbdat(int32_t pos)
721 {
722 return screens[TEMPLATE].data[pos];
723 }
724
725 word zmap::tcmbcset(int32_t pos)
726 {
727 return screens[TEMPLATE].cset[pos];
728 }
729
730 int32_t zmap::tcmbflag(int32_t pos)
731 {
732 return screens[TEMPLATE].sflag[pos];
733 }
734
735 word zmap::tcmbdat2(int32_t pos)
736 {
737 return screens[TEMPLATE2].data[pos];
738 }
739
740 word zmap::tcmbcset2(int32_t pos)
741 {
742 return screens[TEMPLATE2].cset[pos];
743 }
744
745 int32_t zmap::tcmbflag2(int32_t pos)
746 {
747 return screens[TEMPLATE2].sflag[pos];
748 }
749
750 void zmap::TemplateAll()
751 {
752 StartListCommand();
753 for(int32_t i=0; i<128; i++)
754 {
755 if((screens[i].valid&mVALID) && isDungeon(i))
756 DoTemplateCommand(-1, -1, i);
757 }
758 FinishListCommand();
759 }
760
761 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
762 {
763 if(scr==TEMPLATE)
764 return;
765
766 if(!(screens[scr].valid&mVALID))
767 screens[scr].color=Color;
768
769 screens[scr].valid|=mVALID;
770
771 for(int32_t i=0; i<32; i++)
772 {
773 screens[scr].data[i]=screens[TEMPLATE].data[i];
774 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
775 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
776 }
777
778 for(int32_t i=144; i<176; i++)
779 {
780 screens[scr].data[i]=screens[TEMPLATE].data[i];
781 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
782 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
783 }
784
785 for(int32_t y=2; y<=9; y++)
786 {
787 int32_t j=y<<4;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 screens[scr].data[j]=screens[TEMPLATE].data[j];
793 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
794 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
795 ++j;
796 j+=12;
797 screens[scr].data[j]=screens[TEMPLATE].data[j];
798 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
799 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
800 ++j;
801 screens[scr].data[j]=screens[TEMPLATE].data[j];
802 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
803
804 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
805 ++j;
806 }
807
808 if(floorcombo!=-1)
809 {
810 for(int32_t y=2; y<9; y++)
811 for(int32_t x=2; x<14; x++)
812 {
813 int32_t i=(y<<4)+x;
814 screens[scr].data[i] = floorcombo;
815 screens[scr].cset[i] = floorcset;
816 }
817 }
818
819 for(int32_t i=0; i<4; i++)
820 putdoor(scr,i,screens[scr].door[i]);
821 }
822
823
824 void zmap::clearscr(int32_t scr)
825 {
826 screens[scr].zero_memory();
827 screens[scr].valid=mVERSION;
828 for(int q = 0; q < 6; ++q)
829 {
830 auto layer = map_autolayers[cursor.map*6+q];
831 screens[scr].layermap[q] = layer;
832 screens[scr].layerscreen[q] = layer ? scr : 0;
833 }
834 mmap_mark_dirty();
835 }
836
837 const char *loaderror[] =
838 {
839
840 "OK","File not found","Incomplete data",
841 "Invalid version","Invalid file"
842
843 };
844
845 int32_t zmap::load(const char *path)
846 {
847 PACKFILE *f=pack_fopen_password(path,F_READ, "");
848
849 if(!f)
850 return 1;
851
852
853 int16_t version;
854 byte build;
855
856 //get the version
857 if(!p_igetw(&version,f))
858 {
859 goto file_error;
860 }
861
862 //get the build
863 if(!p_getc(&build,f))
864 {
865 goto file_error;
866 }
867
868 for(int32_t i=0; i<MAPSCRS; i++)
869 {
870 mapscr tmpimportscr;
871 tmpimportscr.zero_memory();
872 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
873 {
874 al_trace("failed zmap::load\n");
875 goto file_error;
876 }
877
878 switch(ImportMapBias)
879 {
880 case 0:
881 *(screens+i) = tmpimportscr;
882 break;
883
884 case 1:
885 if(!(screens[i].valid&mVALID))
886 {
887 *(screens+i) = tmpimportscr;
888 }
889 break;
890
891 case 2:
892 if(tmpimportscr.valid&mVALID)
893 {
894 *(screens+i) = tmpimportscr;
895 }
896 break;
897 }
898 }
899
900
901 pack_fclose(f);
902
903 setCurrScr(0);
904 mmap_mark_dirty();
905 regions_mark_dirty();
906 return 0;
907
908 file_error:
909 pack_fclose(f);
910 clearmap(false);
911 return 2;
912 }
913
914 int32_t zmap::save(const char *path)
915 {
916 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
917
918 if(!f)
919 return 1;
920
921 if(!p_iputw(V_MAPS,f))
922 {
923 pack_fclose(f);
924 return 3;
925 }
926
927 // This was the "build number", but that's totally useless here. Keep this junk byte
928 // so as not to totally break exports between ZC versions.
929 if(!p_putc(0,f))
930 {
931 pack_fclose(f);
932 return 3;
933 }
934
935 for(int32_t i=0; i<MAPSCRS; i++)
936 {
937 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
938 {
939 pack_fclose(f);
940 return 2;
941 }
942 }
943
944 pack_fclose(f);
945 return 0;
946 }
947
948
949 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
950 {
951 // Hookshots can be blocked by solid combos on all 3 ground layers.
952 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
953
954 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
955 return true;
956 if (c->walk&(1<<i))
957 return false;
958
959 for(int32_t k=0; k<2; k++)
960 {
961 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
962
963 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
964 {
965 return false;
966 }
967 }
968
969 return true;
970 }
971
972 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
973 {
974 // Hookshots can be blocked by solid combos on all 3 ground layers.
975 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
976
977 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
978 return true;
979 if (c->walk&(1<<i))
980 return false;
981
982 for(int32_t k=0; k<2; k++)
983 {
984 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
985
986 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
987 {
988 return false;
989 }
990 }
991
992 return true;
993 }
994
995 bool zmap::isstepable(int32_t combo)
996 {
997 // This is kind of odd but it's true to the engine (see maps.cpp)
998 return (combo_class_buf[combobuf[combo].type].ladder_pass);
999 }
1000
1001 // Returns the letter of the warp combo.
1002 int32_t zmap::warpindex(int32_t combo)
1003 {
1004 switch(combobuf[combo].type)
1005 {
1006 case cCAVE:
1007 case cPIT:
1008 case cSTAIR:
1009 case cCAVE2:
1010 case cSWIMWARP:
1011 case cDIVEWARP:
1012 case cSWARPA:
1013 return 0;
1014
1015 case cCAVEB:
1016 case cPITB:
1017 case cSTAIRB:
1018 case cCAVE2B:
1019 case cSWIMWARPB:
1020 case cDIVEWARPB:
1021 case cSWARPB:
1022 return 1;
1023
1024 case cCAVEC:
1025 case cPITC:
1026 case cSTAIRC:
1027 case cCAVE2C:
1028 case cSWIMWARPC:
1029 case cDIVEWARPC:
1030 case cSWARPC:
1031 return 2;
1032
1033 case cCAVED:
1034 case cPITD:
1035 case cSTAIRD:
1036 case cCAVE2D:
1037 case cSWIMWARPD:
1038 case cDIVEWARPD:
1039 case cSWARPD:
1040 return 3;
1041
1042 case cPITR:
1043 case cSTAIRR:
1044 case cSWARPR:
1045 return 4;
1046 }
1047
1048 return -1;
1049
1050 }
1051
1052 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1053 {
1054 if(top)
1055 line(dest,x,y,x+15,y,c);
1056 rectfill(dest,x,y,x+3,y+15,c);
1057 rectfill(dest,x+12,y,x+15,y+15,c);
1058 rectfill(dest,x+4,y+2,x+11,y+5,c);
1059 rectfill(dest,x+4,y+10,x+11,y+13,c);
1060 }
1061
1062 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1063 {
1064 line(dest,x,y,x+15,y,c);
1065 }
1066
1067 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1068 {
1069 int32_t cx = COMBOX(pos);
1070 int32_t cy = COMBOY(pos);
1071
1072 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1073
1074 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1075
1076 int32_t bridgedetected = 0;
1077
1078 for(int32_t i=0; i<4; i++)
1079 {
1080 int32_t tx=((i&2)<<2)+x;
1081 int32_t ty=((i&1)<<3)+y;
1082 int32_t tx2=((i&2)<<2)+cx;
1083 int32_t ty2=((i&1)<<3)+cy;
1084 for (int32_t m = layer; m <= 1; m++)
1085 {
1086 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1087 {
1088 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1089 {
1090 bridgedetected |= (1<<i);
1091 }
1092 }
1093 else
1094 {
1095 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1096 {
1097 bridgedetected |= (1<<i);
1098 }
1099 }
1100 }
1101 if (bridgedetected & (1<<i))
1102 {
1103 if (i >= 3) break;
1104 else continue;
1105 }
1106 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1107 {
1108 for(int32_t k=0; k<8; k+=2)
1109 for(int32_t j=0; j<8; j+=2)
1110 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1111 }
1112 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1113 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1114
1115 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1116 {
1117 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1118 {
1119 for(int32_t k=0; k<8; k+=2)
1120 for(int32_t j=0; j<8; j+=2)
1121 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1122 }
1123 else
1124 {
1125 int32_t color = COLOR_SOLID;
1126
1127 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1128 color=vc(6);
1129 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1130 color=vc(7);
1131
1132 rectfill(dest,tx,ty,tx+7,ty+7,color);
1133 }
1134 }
1135 }
1136
1137 bridgedetected = 0;
1138 for(int32_t i=0; i<4; i++)
1139 {
1140 int32_t tx2=((i&2)<<2)+cx;
1141 int32_t ty2=((i&1)<<3)+cy;
1142 for (int32_t m = 0; m <= 1; m++)
1143 {
1144 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1145 {
1146 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1147 {
1148 bridgedetected |= (1<<i);
1149 }
1150 }
1151 else
1152 {
1153 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1154 {
1155 bridgedetected |= (1<<i);
1156 }
1157 }
1158 }
1159 }
1160
1161 // Draw damage combos
1162 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1163 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1164 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1165 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1166 || combo_class_buf[c1.type].modify_hp_amount
1167 || combo_class_buf[c2.type].modify_hp_amount;
1168
1169 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1170
1171 if(dmg)
1172 {
1173 if (bridgedetected <= 0)
1174 {
1175 for(int32_t k=0; k<16; k+=2)
1176 for(int32_t j=0; j<16; j+=2)
1177 if(((k+j)/2)%2)
1178 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1179 }
1180 else
1181 {
1182 for(int32_t i=0; i<4; i++)
1183 {
1184 if (!(bridgedetected & (1<<i)))
1185 {
1186 int32_t tx=((i&2)<<2)+x;
1187 int32_t ty=((i&1)<<3)+y;
1188 for(int32_t k=0; k<8; k+=2)
1189 for(int32_t j=0; j<8; j+=2)
1190 if(((k+j)/2)%2)
1191 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1192 }
1193 }
1194 }
1195 }
1196
1197 if(c.type == cSLOPE)
1198 {
1199 slope_info s(c, x, y);
1200 s.draw(dest, 0, 0, COLOR_SLOPE);
1201 }
1202 auto fl0 = MAPFLAG2(-1,cx,cy);
1203 auto fl1 = MAPFLAG2(0,cx,cy);
1204 auto fl2 = MAPFLAG2(1,cx,cy);
1205 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1206 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1207 {
1208 bool top = false;
1209 if(cy)
1210 {
1211 top = true;
1212 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1213 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1214 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1215 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1216 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1217 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1218 {
1219 top = false;
1220 }
1221 }
1222 draw_ladder(dest,x,y,COLOR_LADDER,top);
1223 }
1224 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1225 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1226 {
1227 draw_platform(dest,x,y,COLOR_LADDER);
1228 }
1229 }
1230
1231 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1232 {
1233 int32_t cx = COMBOX(pos);
1234 int32_t cy = COMBOY(pos);
1235
1236 if (screen < 0) return;
1237 if (map < 0) return;
1238
1239 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1240
1241 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1242
1243 int32_t bridgedetected = 0;
1244 for(int32_t i=0; i<4; i++)
1245 {
1246 int32_t tx=((i&2)<<2)+x;
1247 int32_t ty=((i&1)<<3)+y;
1248 int32_t tx2=((i&2)<<2)+cx;
1249 int32_t ty2=((i&1)<<3)+cy;
1250 for (int32_t m = layer; m <= 1; m++)
1251 {
1252 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1253 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1254 {
1255 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1256 {
1257 bridgedetected |= (1<<i);
1258 }
1259 }
1260 else
1261 {
1262 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1263 {
1264 bridgedetected |= (1<<i);
1265 }
1266 }
1267 }
1268 if (bridgedetected & (1<<i))
1269 {
1270 continue;
1271 }
1272 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1273 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1274
1275
1276 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1277 {
1278 for(int32_t k=0; k<8; k+=2)
1279 for(int32_t j=0; j<8; j+=2)
1280 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1281 }
1282 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1283 {
1284 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1285 {
1286 for(int32_t k=0; k<8; k+=2)
1287 for(int32_t j=0; j<8; j+=2)
1288 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1289 }
1290 else
1291 {
1292 int32_t color = COLOR_SOLID;
1293
1294 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1295 color=vc(6);
1296 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1297 color=vc(7);
1298
1299 rectfill(dest,tx,ty,tx+7,ty+7,color);
1300 }
1301 }
1302 }
1303
1304 bridgedetected = 0;
1305 for(int32_t i=0; i<4; i++)
1306 {
1307 int32_t tx2=((i&2)<<2)+cx;
1308 int32_t ty2=((i&1)<<3)+cy;
1309 for (int32_t m = 0; m <= 1; m++)
1310 {
1311 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1312 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1313 {
1314 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1315 {
1316 bridgedetected |= (1<<i);
1317 }
1318 }
1319 else
1320 {
1321 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1322 {
1323 bridgedetected |= (1<<i);
1324 }
1325 }
1326 }
1327 }
1328
1329 // Draw damage combos
1330 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1331 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1332 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1333 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1334 || combo_class_buf[c1.type].modify_hp_amount
1335 || combo_class_buf[c2.type].modify_hp_amount;
1336
1337 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1338
1339 if(dmg)
1340 {
1341 if (bridgedetected <= 0)
1342 {
1343 for(int32_t k=0; k<16; k+=2)
1344 for(int32_t j=0; j<16; j+=2)
1345 if(((k+j)/2)%2)
1346 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1347 }
1348 else
1349 {
1350 for(int32_t i=0; i<4; i++)
1351 {
1352 if (!(bridgedetected & (1<<i)))
1353 {
1354 int32_t tx=((i&2)<<2)+x;
1355 int32_t ty=((i&1)<<3)+y;
1356 for(int32_t k=0; k<8; k+=2)
1357 for(int32_t j=0; j<8; j+=2)
1358 if(((k+j)/2)%2)
1359 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1360 }
1361 }
1362 }
1363 }
1364
1365 if(c.type == cSLOPE)
1366 {
1367 slope_info s(c, x, y);
1368 s.draw(dest, 0, 0, COLOR_SLOPE);
1369 }
1370 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1371 auto fl1 = MAPFLAG3(map,screen,0,pos);
1372 auto fl2 = MAPFLAG3(map,screen,1,pos);
1373 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1374 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1375 {
1376 bool top = false;
1377 if(cy)
1378 {
1379 top = true;
1380 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1381 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1382 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1383 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1384 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1385 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1386 {
1387 top = false;
1388 }
1389 }
1390 draw_ladder(dest,x,y,COLOR_LADDER,top);
1391 }
1392 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1393 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1394 {
1395 draw_platform(dest,x,y,COLOR_LADDER);
1396 }
1397 }
1398
1399 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1400 {
1401 const newcombo& c = combobuf[cmbdat];
1402
1403 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1404
1405 for(int32_t i=0; i<4; i++)
1406 {
1407 int32_t tx=((i&2)<<2)+x;
1408 int32_t ty=((i&1)<<3)+y;
1409
1410 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1411 {
1412 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1413 {
1414 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1415 }
1416 else
1417 {
1418 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1419 }
1420 }
1421
1422
1423 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1424 {
1425 for(int32_t k=0; k<8; k+=2)
1426 for(int32_t j=0; j<8; j+=2)
1427 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1428 }
1429 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1430 {
1431 if(c.type==cLADDERHOOKSHOT)
1432 {
1433 for(int32_t k=0; k<8; k+=2)
1434 for(int32_t j=0; j<8; j+=2)
1435 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1436 }
1437 else
1438 {
1439 int32_t color = COLOR_SOLID;
1440
1441 if(c.type==cLADDERONLY)
1442 color=vc(6);
1443 else if(c.type==cHOOKSHOTONLY)
1444 color=vc(7);
1445
1446 rectfill(dest,tx,ty,tx+7,ty+7,color);
1447 }
1448 }
1449
1450 // Draw damage combos
1451 if(combo_class_buf[c.type].modify_hp_amount != 0)
1452 {
1453 for(int32_t k=0; k<8; k+=2)
1454 for(int32_t j=0; j<8; j+=2)
1455 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1456 }
1457 }
1458
1459 if(c.type == cSLOPE)
1460 {
1461 slope_info s(c, 0, 0);
1462 zfix const& slope = s.slope();
1463
1464 BITMAP* sub = create_bitmap_ex(8,16,16);
1465 clear_bitmap(sub);
1466 s.draw(sub, 0, 0, COLOR_SLOPE);
1467 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1468 destroy_bitmap(sub);
1469 }
1470 if(c.flag == mfSIDEVIEWLADDER)
1471 {
1472 draw_ladder(dest,x,y,COLOR_LADDER);
1473 }
1474 else if(c.flag == mfSIDEVIEWPLATFORM)
1475 {
1476 draw_platform(dest,x,y,COLOR_LADDER);
1477 }
1478 }
1479
1480 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1481 {
1482 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1483 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1484 }
1485 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1486 {
1487
1488 newcombo const& c = combobuf[cmbdat];
1489
1490 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1491 {
1492 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1493 // text_mode(-1);
1494 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1495 if(sflag)
1496 {
1497 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1498 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1499 }
1500
1501 if(c.flag)
1502 {
1503 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1504 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1505 }
1506 }
1507
1508 if(flags&cCSET)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 // text_mode(inv?vc(15):vc(0));
1512 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1513 }
1514 else if(flags&cCTYPE)
1515 {
1516 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1517 // text_mode(inv?vc(15):vc(0));
1518 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1519 }
1520 }
1521
1522 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1523 {
1524 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1525
1526 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1527 if(repos)
1528 {
1529 combotile_override_x = x+(8*(scale-1));
1530 combotile_override_y = y+(8*(scale-1));
1531 }
1532 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1533 if(repos) combotile_override_x = combotile_override_y = -1;
1534 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1535 destroy_bitmap(b);
1536 }
1537 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1538 {
1539 static newcombo nilcombo;
1540 nilcombo.tile = 0;
1541
1542 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1543
1544 if(c.tile==0)
1545 {
1546 rectfill(dest,x,y,x+15,y+15,vc(0));
1547 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1548 return;
1549 }
1550
1551 putcombo(dest,x,y,cmbdat,cset);
1552
1553 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1554 {
1555 if(sflag)
1556 {
1557 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1558 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1559 }
1560
1561 if(combobuf[cmbdat].flag)
1562 {
1563 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1564 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1565 }
1566 }
1567
1568 if(flags&cWALK)
1569 {
1570 put_walkflags(dest,x,y,cmbdat,0);
1571 }
1572
1573 if(flags&cCSET)
1574 {
1575 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1576 // text_mode(inv?vc(15):vc(0));
1577 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1578 }
1579 else if(flags&cCTYPE)
1580 {
1581 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1582 // text_mode(inv?vc(15):vc(0));
1583 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1584 }
1585 }
1586 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1587 {
1588 auto blitx = 1 + (slot % 16) * 17;
1589 auto blity = 1 + (slot / 16) * 17;
1590 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1591 }
1592
1593
1594 void copy_mapscr(mapscr *dest, const mapscr *src)
1595 {
1596 if(!dest || !src) return;
1597 *dest = *src;
1598 }
1599
1600 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1601 {
1602 int32_t x=0,y=0;
1603 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1604
1605 switch(side)
1606 {
1607 case up:
1608 case down:
1609 x=((pos&15)<<4)+xofs;
1610 y=(ignorepos?0:(pos&0xF0))+yofs;
1611 break;
1612
1613 case left:
1614 case right:
1615 x=(ignorepos?0:((pos&15)<<4))+xofs;
1616 y=(pos&0xF0)+yofs;
1617 break;
1618 }
1619
1620 switch(type)
1621 {
1622 case dt_lock:
1623 case dt_shut:
1624 case dt_boss:
1625 case dt_bomb:
1626 switch(side)
1627 {
1628 case up:
1629 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1630 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1631 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1633 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1635 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1636 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1637 break;
1638
1639 case down:
1640 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1641 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1642 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1644 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1646 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1647 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1648 break;
1649
1650 case left:
1651 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1653 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1655 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1656 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1657
1658 if(x+16 >= dest->w)
1659 break;
1660
1661 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1663 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1665 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1666 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1667 break;
1668
1669 case right:
1670
1671 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1673 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1675 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1676 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1677
1678 if(x+16 <= 0)
1679 break;
1680
1681 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1682 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1683 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1684 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1685 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1686 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1687 break;
1688 }
1689
1690 break;
1691
1692 case dt_pass:
1693 case dt_wall:
1694 case dt_walk:
1695 default:
1696 break;
1697 }
1698 }
1699
1700 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1701 {
1702 int32_t x=((pos&15)<<4)+xofs;
1703 int32_t y=(pos&0xF0)+yofs;
1704 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1705
1706
1707 switch(side)
1708 {
1709 case up:
1710 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1711 {
1712 overcombo(dest,x,y,
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1714 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1715 }
1716
1717 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1718 {
1719 overcombo(dest,x+16,y,
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1721
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1723 }
1724
1725 break;
1726
1727 case down:
1728 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1729 {
1730 overcombo(dest,x,y,
1731 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1732 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1733 }
1734
1735 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1736 {
1737 overcombo(dest,x+16,y,
1738 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1740 }
1741
1742 break;
1743
1744 case left:
1745 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1746 {
1747 overcombo(dest,x,y,
1748 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1749 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1750 }
1751
1752 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1753 {
1754 overcombo(dest,x,y+16,
1755 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1756 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1757 }
1758
1759 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1760 {
1761 overcombo(dest,x,y+32,
1762 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1764 }
1765
1766 break;
1767
1768 case right:
1769 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1770 {
1771 overcombo(dest,x,y,
1772 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1773 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1774 }
1775
1776 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1777 {
1778 overcombo(dest,x,y+16,
1779
1780 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1781 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1782 }
1783
1784 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1785 {
1786 overcombo(dest,x,y+32,
1787 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1788 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1789 }
1790
1791 break;
1792 }
1793 }
1794
1795 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1796 {
1797 word cmbcheck1, cmbcheck2;
1798 newcombo combocheck1, combocheck2;
1799 combocheck1 = combobuf[0];
1800 combocheck2 = combobuf[0];
1801 combocheck1.walk = 0;
1802 combocheck2.walk = 0;
1803
1804 int32_t layermap, layerscreen;
1805
1806 switch(dir)
1807 {
1808 case up:
1809 {
1810 if(i>15) //not top row of combos
1811 {
1812 return false;
1813 }
1814
1815 if(screen<16) //top row of screens
1816 {
1817 return false;
1818
1819 }
1820
1821 //check main screen
1822 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1823 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1824 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1825 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1826
1827 //check layer 1
1828 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1829
1830 if(layermap>-1 && layermap<map_count)
1831 {
1832 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1833 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1834 if (combobuf[cmbcheck1].type == cBRIDGE)
1835 {
1836 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1837 {
1838 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1839 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1840 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1841 }
1842 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1843 }
1844 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1845 }
1846
1847 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1848
1849 if(layermap>-1 && layermap<map_count)
1850 {
1851 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1852 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1853 if (combobuf[cmbcheck2].type == cBRIDGE)
1854 {
1855 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1856 {
1857 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1858 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1859 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1860 }
1861 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1862 }
1863 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1864 }
1865
1866 //check layer 2
1867 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1868
1869 if(layermap>-1 && layermap<map_count)
1870 {
1871 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1872
1873 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1874 if (combobuf[cmbcheck2].type == cBRIDGE)
1875 {
1876 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1877 {
1878 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1879 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1880 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1881 }
1882 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1883 }
1884 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1885 }
1886
1887 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1888
1889 if(layermap>-1 && layermap<map_count)
1890 {
1891 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1892 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1893 if (combobuf[cmbcheck2].type == cBRIDGE)
1894 {
1895 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1896 {
1897 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1898 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1899 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1900 }
1901 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1902 }
1903 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1904 }
1905
1906 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1907 {
1908 return true;
1909 }
1910
1911 break;
1912 }
1913 case down:
1914 {
1915 if(i<160) //not bottom row of combos
1916 {
1917 return false;
1918 }
1919
1920 if(screen>111) //bottom row of screens
1921 {
1922 return false;
1923 }
1924
1925 //check main screen
1926 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1927 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1928 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1929 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1930
1931
1932 //check layer 1
1933 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1934
1935 if(layermap>-1 && layermap<map_count)
1936 {
1937 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1938 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1939 if (combobuf[cmbcheck1].type == cBRIDGE)
1940 {
1941 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1942 {
1943 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1944 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1945 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1946 }
1947 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1948 }
1949 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1950 }
1951
1952 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1953
1954 if(layermap>-1 && layermap<map_count)
1955 {
1956 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1957 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1958 if (combobuf[cmbcheck2].type == cBRIDGE)
1959 {
1960 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1961 {
1962 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1963 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1964 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1965 }
1966 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1967 }
1968 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1969 }
1970
1971 //check layer 2
1972 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1973
1974 if(layermap>-1 && layermap<map_count)
1975 {
1976 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1977 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1978 if (combobuf[cmbcheck1].type == cBRIDGE)
1979 {
1980 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1981 {
1982 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1983 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1984 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1985 }
1986 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1987 }
1988 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1989 }
1990
1991 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1992
1993 if(layermap>-1 && layermap<map_count)
1994 {
1995 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1996 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1997 if (combobuf[cmbcheck2].type == cBRIDGE)
1998 {
1999 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2000 {
2001 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2002 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2003 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2004 }
2005 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2006 }
2007 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2008 }
2009
2010 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2011 {
2012 return true;
2013 }
2014
2015 break;
2016 }
2017 case left:
2018 {
2019 if((i&0xF)!=0) //not left column of combos
2020 {
2021 return false;
2022 }
2023
2024 if((screen&0xF)==0) //left column of screens
2025 {
2026 return false;
2027 }
2028
2029 //check main screen
2030 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2031 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2032 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2033 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2034
2035 //check layer 1
2036 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2037
2038 if(layermap>-1 && layermap<map_count)
2039 {
2040 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2041 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2042 if (combobuf[cmbcheck1].type == cBRIDGE)
2043 {
2044 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2045 {
2046 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2047 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2048 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2049 }
2050 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2051 }
2052 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2053 }
2054
2055 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2056
2057 if(layermap>-1 && layermap<map_count)
2058 {
2059 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2060 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2061 if (combobuf[cmbcheck2].type == cBRIDGE)
2062 {
2063 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2064 {
2065 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2066 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2067 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2068 }
2069 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2070 }
2071 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2072 }
2073
2074 //check layer 2
2075 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2076
2077 if(layermap>-1 && layermap<map_count)
2078 {
2079 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2080 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2081 if (combobuf[cmbcheck1].type == cBRIDGE)
2082 {
2083 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2084 {
2085 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2086 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2087 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2088 }
2089 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2090 }
2091 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2092 }
2093
2094 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2095
2096 if(layermap>-1 && layermap<map_count)
2097 {
2098 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2099 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2100 if (combobuf[cmbcheck2].type == cBRIDGE)
2101 {
2102 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2103 {
2104 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2105 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2106 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2107 }
2108 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2109 }
2110 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2111 }
2112
2113 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2114 {
2115 return true;
2116 }
2117
2118 break;
2119 }
2120 case right:
2121 {
2122 if((i&0xF)!=15) //not right column of combos
2123 {
2124 return false;
2125 }
2126
2127 if((screen&0xF)==15) //right column of screens
2128 {
2129 return false;
2130 }
2131
2132 //check main screen
2133 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2134 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2135 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2136 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2137
2138 //check layer 1
2139 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2140
2141 if(layermap>-1 && layermap<map_count)
2142 {
2143 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2144 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2145 if (combobuf[cmbcheck1].type == cBRIDGE)
2146 {
2147 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2148 {
2149 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2150 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2151 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2152 }
2153 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2154 }
2155 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2156 }
2157
2158 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2159
2160 if(layermap>-1 && layermap<map_count)
2161 {
2162 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2163 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2164 if (combobuf[cmbcheck2].type == cBRIDGE)
2165 {
2166 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2167 {
2168 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2169 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2170 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2171 }
2172 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2173 }
2174 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2175 }
2176
2177 //check layer 2
2178 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2179
2180 if(layermap>-1 && layermap<map_count)
2181 {
2182 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2183 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2184 if (combobuf[cmbcheck1].type == cBRIDGE)
2185 {
2186 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2187 {
2188 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2189 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2190 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2191 }
2192 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2193 }
2194 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2195 }
2196
2197 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2198
2199 if(layermap>-1 && layermap<map_count)
2200 {
2201 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2202
2203 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2204 if (combobuf[cmbcheck2].type == cBRIDGE)
2205 {
2206 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2207 {
2208 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2209 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2210 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2211 }
2212 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2213 }
2214 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2215 }
2216
2217 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2218 {
2219 return true;
2220 }
2221
2222 break;
2223 }
2224 }
2225
2226 return false;
2227 }
2228
2229 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2230 {
2231 int32_t checkcombo;
2232
2233 if(alignment_arrow_timer>31)
2234 {
2235 if(scr<0)
2236 {
2237 scr=cursor.screen;
2238 }
2239
2240 if((scr<128)) //do the misalignment arrows
2241 {
2242 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2243 {
2244 if(misaligned(cursor.map, scr, checkcombo, up))
2245 {
2246 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2247 }
2248 }
2249
2250 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2251 {
2252 if(misaligned(cursor.map, scr, checkcombo, down))
2253 {
2254 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2255 }
2256 }
2257
2258 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2259 {
2260 if(misaligned(cursor.map, scr, checkcombo, left))
2261 {
2262 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2263 }
2264 }
2265
2266 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2267 {
2268 if(misaligned(cursor.map, scr, checkcombo, right))
2269 {
2270 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2271 }
2272 }
2273
2274 int32_t tempalign;
2275
2276 //check top left corner
2277 checkcombo=0;
2278 tempalign=0;
2279 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2280 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2281
2282 switch(tempalign)
2283 {
2284 case 0:
2285 break;
2286
2287 case 1: //up
2288 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2289 break;
2290
2291 case 2: //left
2292 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2293 break;
2294
2295 case 3: //up-left
2296 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2297 break;
2298 }
2299
2300 //check top right corner
2301 checkcombo=15;
2302 tempalign=0;
2303 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2304 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2305
2306 switch(tempalign)
2307 {
2308 case 0:
2309 break;
2310
2311 case 1: //up
2312 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2313 break;
2314
2315 case 2: //right
2316 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2317 break;
2318
2319 case 3: //up-right
2320 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2321 break;
2322 }
2323
2324 //check bottom left corner
2325 checkcombo=160;
2326 tempalign=0;
2327 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2328 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2329
2330 switch(tempalign)
2331 {
2332 case 0:
2333 break;
2334
2335 case 1: //down
2336 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2337 break;
2338
2339 case 2: //left
2340 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2341 break;
2342
2343 case 3: //down-left
2344 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2345 break;
2346 }
2347
2348 //check bottom right corner
2349
2350 checkcombo=175;
2351 tempalign=0;
2352 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2353 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2354
2355 switch(tempalign)
2356 {
2357 case 0:
2358 break;
2359
2360 case 1: //down
2361 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2362 break;
2363
2364 case 2: //right
2365 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2366 break;
2367
2368 case 3: //down-right
2369 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2370 break;
2371 }
2372 }
2373 }
2374 }
2375
2376 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2377 {
2378 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2379 }
2380
2381 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2382 {
2383 if (map < 0 || screen < 0) return 0;
2384
2385 if(pos>175 || pos < 0)
2386 return 0;
2387
2388 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2389
2390 if (!m->is_valid()) return 0;
2391
2392 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2393
2394 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2395
2396 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2397
2398 if (!scr->is_valid()) return 0;
2399
2400 return scr->data[pos]; // entire combo code
2401 }
2402
2403 // Takes array index layer num., not actual layer num.
2404 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2405 {
2406 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2407
2408 if(map<0)
2409 map=cursor.map;
2410
2411 if(scr<0)
2412 scr=cursor.screen;
2413
2414 mapscr *screen1;
2415
2416 if(prv_mode)
2417 {
2418 screen1=get_prvscr();
2419 }
2420 else
2421 {
2422 screen1=AbsoluteScr(cursor.map,cursor.screen);
2423 }
2424
2425 int32_t layermap;
2426 layermap=screen1->layermap[lyr]-1;
2427
2428 if(layermap<0 || layermap >= map_count) return 0;
2429
2430 mapscr *layer;
2431
2432 if(prv_mode)
2433 layer = &prvlayers[lyr];
2434 else
2435 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2436
2437 int32_t pos = COMBOPOS(x,y);
2438
2439 if(pos>175 || pos < 0)
2440 return 0;
2441
2442 return layer->data[pos];
2443 }
2444
2445 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2446 {
2447 if(map<0)
2448 map=cursor.map;
2449
2450 if(scr<0)
2451 scr=cursor.screen;
2452
2453 mapscr *screen1;
2454
2455 if(prv_mode)
2456 {
2457 screen1=get_prvscr();
2458 }
2459 else
2460 {
2461 screen1=AbsoluteScr(cursor.map,cursor.screen);
2462 }
2463
2464 x = vbound(x, 0, 16*16);
2465 y = vbound(y, 0, 11*16);
2466 int32_t combo = COMBOPOS(x,y);
2467
2468 if(combo>175 || combo < 0)
2469 return 0;
2470
2471 return screen1->data[combo];
2472 }
2473
2474 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2475 {
2476 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2477 }
2478
2479 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2480 {
2481 if (map < 0 || screen < 0) return 0;
2482
2483 if(pos>175 || pos < 0)
2484 return 0;
2485
2486 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2487
2488 if (!m->is_valid()) return 0;
2489
2490 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2491
2492 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2493
2494 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2495
2496 if (!scr->is_valid()) return 0;
2497
2498 return scr->sflag[pos]; // entire combo code
2499 }
2500
2501 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2502 {
2503 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2504
2505 if(map<0)
2506 map=cursor.map;
2507
2508 if(scr<0)
2509 scr=cursor.screen;
2510
2511 mapscr *screen1;
2512
2513 if(prv_mode)
2514 {
2515 screen1=get_prvscr();
2516 }
2517 else
2518 {
2519 screen1=AbsoluteScr(cursor.map,cursor.screen);
2520 }
2521
2522 int32_t layermap;
2523 layermap=screen1->layermap[lyr]-1;
2524
2525 if(layermap<0 || layermap >= map_count) return 0;
2526
2527 mapscr *layer;
2528
2529 if(prv_mode)
2530 layer = &prvlayers[lyr];
2531 else
2532 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2533
2534 int32_t combo = COMBOPOS(x,y);
2535
2536 if(combo>175 || combo < 0)
2537 return 0;
2538
2539 return layer->sflag[combo];
2540 }
2541
2542 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2543 {
2544 if(map<0)
2545 map=cursor.map;
2546
2547 if(scr<0)
2548 scr=cursor.screen;
2549
2550 mapscr *screen1;
2551
2552 if(prv_mode)
2553 {
2554 screen1=get_prvscr();
2555 }
2556 else
2557 {
2558 screen1=AbsoluteScr(cursor.map,cursor.screen);
2559 }
2560
2561 x = vbound(x, 0, 16*16);
2562 y = vbound(y, 0, 11*16);
2563 int32_t combo = COMBOPOS(x,y);
2564
2565 if(combo>175 || combo < 0)
2566 return 0;
2567
2568 return screen1->sflag[combo];
2569 }
2570
2571 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2572 {
2573 mapscr *layers[7];
2574 mapscr *basescr;
2575 if(prv_mode)
2576 {
2577 layers[0] = &prvscr;
2578 basescr = layers[0];
2579 for(auto q = 1; q < 7; ++q)
2580 {
2581 if(prvlayers[q-1].valid)
2582 layers[q] = &(prvlayers[q-1]);
2583 else layers[q] = NULL;
2584 }
2585 }
2586 else
2587 {
2588 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2589 basescr = layers[0];
2590 for(auto q = 1; q < 7; ++q)
2591 {
2592 int32_t lmap = basescr->layermap[q-1]-1;
2593 int32_t lscr = basescr->layerscreen[q-1];
2594 if(lmap < 0)
2595 layers[q] = NULL;
2596 else layers[q] = AbsoluteScr(lmap, lscr);
2597 }
2598 }
2599 for(auto q = 0; q < 7; ++q)
2600 {
2601 if(!layers[q]) continue;
2602 for(auto pos = 0; pos < 176; ++pos)
2603 {
2604 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2605 if(cmb.type == cTORCH)
2606 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2607 }
2608 }
2609 word maxffc = basescr->numFFC();
2610 for(auto q = 0; q < maxffc; ++q)
2611 {
2612 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2613 if(cmb.type == cTORCH)
2614 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2615 }
2616 }
2617
2618 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2619 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2620 {
2621 newcombo const& cmb = combobuf[cid];
2622 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2623 if(dither)
2624 {
2625 if (LayerDitherSz == 0)
2626 return;
2627 BITMAP* buf = create_bitmap_ex(8,16,16);
2628 clear_bitmap(buf);
2629 overcombo(buf,0,0,cid,cset);
2630 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2631 if(over)
2632 {
2633 if(transp)
2634 {
2635 color_map = &trans_table2;
2636 draw_trans_sprite(dest, buf, x, y);
2637 color_map = &trans_table;
2638 }
2639 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2640 }
2641 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2642 destroy_bitmap(buf);
2643 }
2644 else if(over)
2645 {
2646 if(transp)
2647 overcombotranslucent(dest,x,y,cid,cset,0);
2648 else overcombo(dest,x,y,cid,cset);
2649 }
2650 else put_combo(dest,x,y,cid,cset,flags,sflag);
2651 }
2652 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2653 {
2654 if(!md) return;
2655 for (int32_t i = 0; i < 176; i++)
2656 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2657 }
2658 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2659 {
2660 if(!md) return;
2661 for (int32_t i = 0; i < 176; i++)
2662 {
2663 int data = md->data[i];
2664 if(combo_class_buf[combobuf[data].type].overhead)
2665 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2666 }
2667 }
2668 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2669 {
2670 if(!LayerMaskInt[lyr])
2671 return nullptr;
2672 if(lyr == 0)
2673 return basescr;
2674 int layermap = basescr->layermap[lyr-1]-1;
2675
2676 if(layermap>-1 && layermap<map_count)
2677 {
2678 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2679 return &TheMaps[layerscreen];
2680 }
2681 return nullptr;
2682 }
2683 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2684 {
2685 int num_ffcs = basescr->numFFC();
2686 for(int32_t i=num_ffcs-1; i>=0; i--)
2687 {
2688 auto const& ff = basescr->ffcs[i];
2689 if(ff.data)
2690 {
2691 if(!(ff.flags&ffc_changer))
2692 {
2693 int32_t tx=(ff.x.getInt())+x;
2694 int32_t ty=(ff.y.getInt())+y;
2695
2696 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2697 {
2698 if(ff.flags&ffc_trans)
2699 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2700 else
2701 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2702 }
2703 }
2704 }
2705 }
2706 }
2707 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2708 {
2709 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2710 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2711
2712 if(map<0)
2713 map=cursor.map;
2714
2715 if(screen<0)
2716 screen=cursor.screen;
2717
2718 mapscr *basescr;
2719 mapscr* layers[7] = {nullptr};
2720
2721 if(prv_mode)
2722 {
2723 hl_layer = -1;
2724 basescr=get_prvscr();
2725 }
2726 else
2727 {
2728 basescr=AbsoluteScr(map,screen);
2729 }
2730 layers[0] = _zmap_get_lyr_checked(0,basescr);
2731 for(int lyr = 1; lyr < 7; ++lyr)
2732 {
2733 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2734 : _zmap_get_lyr_checked(lyr,basescr);
2735 }
2736
2737 if(!(basescr->valid&mVALID))
2738 {
2739 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2740 rectfill(dest,x,y,x+255,y+175,vc(1));
2741
2742 if(ShowMisalignments)
2743 {
2744 check_alignments(dest,x,y,screen);
2745 }
2746
2747 return;
2748 }
2749
2750 if(LayerMaskInt[0]==0)
2751 {
2752 byte bgfill = 0;
2753 if (LayerDitherBG > -1)
2754 bgfill = vc(LayerDitherBG);
2755 rectfill(dest,x,y,x+255,y+175,bgfill);
2756 }
2757
2758 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2759 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2760 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2761
2762 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2763 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2764 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2765
2766 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2767 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2768
2769 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2770 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2771
2772 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2773 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2774 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2775
2776 int32_t doortype[4];
2777
2778 for(int32_t i=0; i<4; i++)
2779 {
2780 switch(basescr->door[i])
2781 {
2782 case dOPEN:
2783 doortype[i]=dt_pass;
2784 break;
2785
2786 case dLOCKED:
2787 doortype[i]=dt_lock;
2788 break;
2789
2790 case d1WAYSHUTTER:
2791 case dSHUTTER:
2792 doortype[i]=dt_shut;
2793 break;
2794
2795 case dBOSS:
2796 doortype[i]=dt_boss;
2797 break;
2798
2799 case dBOMB:
2800 doortype[i]=dt_bomb;
2801 break;
2802 }
2803 }
2804
2805 switch(basescr->door[up])
2806 {
2807 case dBOMB:
2808 over_door(dest,39,up,x,y,false, screen);
2809 [[fallthrough]];
2810 case dOPEN:
2811 case dLOCKED:
2812 case d1WAYSHUTTER:
2813 case dSHUTTER:
2814 case dBOSS:
2815 put_door(dest,7,up,doortype[up],x,y,false,screen);
2816 break;
2817
2818 case dWALK:
2819 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2820 {
2821 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2822 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2823 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2824 }
2825 else
2826
2827 {
2828 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2829 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2830 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2831 }
2832
2833 break;
2834 }
2835
2836 switch(basescr->door[down])
2837 {
2838 case dBOMB:
2839 over_door(dest,135,down,x,y,false,screen);
2840 [[fallthrough]];
2841 case dOPEN:
2842 case dLOCKED:
2843 case d1WAYSHUTTER:
2844 case dSHUTTER:
2845 case dBOSS:
2846 put_door(dest,151,down,doortype[down],x,y,false,screen);
2847 break;
2848
2849 case dWALK:
2850 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2851 {
2852 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2853 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2854 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2855 }
2856 else
2857 {
2858 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2859 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2860 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2861 }
2862
2863 break;
2864 }
2865
2866 switch(basescr->door[left])
2867 {
2868 case dBOMB:
2869 over_door(dest,66,left,x,y,false,screen);
2870 [[fallthrough]];
2871 case dOPEN:
2872 case dLOCKED:
2873 case d1WAYSHUTTER:
2874 case dSHUTTER:
2875 case dBOSS:
2876 put_door(dest,64,left,doortype[left],x,y,false,screen);
2877 break;
2878
2879 case dWALK:
2880 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2881 {
2882 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2883 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2884 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2885 }
2886 else
2887 {
2888 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2889 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2890 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2891 }
2892
2893 break;
2894 }
2895
2896 switch(basescr->door[right])
2897 {
2898
2899 case dBOMB:
2900 over_door(dest,77,right,x,y,false,screen);
2901 [[fallthrough]];
2902 case dOPEN:
2903 case dLOCKED:
2904 case d1WAYSHUTTER:
2905 case dSHUTTER:
2906 case dBOSS:
2907 put_door(dest,78,right,doortype[right],x,y,false,screen);
2908 break;
2909
2910 case dWALK:
2911 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2912 {
2913 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2914 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2915 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2916 }
2917 else
2918 {
2919 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2920 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2921 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2922 }
2923
2924 break;
2925 }
2926
2927 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2928 {
2929 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2930 }
2931
2932 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2933 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2934 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2935
2936 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2937 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2938
2939 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2940
2941 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2942 {
2943 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2944 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2945 }
2946 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2947 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2948
2949 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2950
2951 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2952 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2953 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2954
2955 int num_ffcs = basescr->numFFC();
2956 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2957 if(basescr->ffcs[i].data)
2958 if(basescr->ffcs[i].flags&ffc_changer)
2959 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2960
2961 if(flags&cWALK)
2962 {
2963 if(layers[0])
2964 for(int32_t i=0; i<176; i++)
2965 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2966
2967 for(int32_t k=0; k<2; k++)
2968 {
2969 if(layers[k+1])
2970 for(int32_t i=0; i<176; i++)
2971 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2972 }
2973 for(int32_t i=num_ffcs-1; i>=0; i--)
2974 {
2975 if(auto data = basescr->ffcs[i].data)
2976 {
2977 if(!(basescr->ffcs[i].flags&ffc_changer))
2978 {
2979 newcombo const& cmb = combobuf[data];
2980 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2981 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2982
2983 if(basescr->ffcs[i].flags&ffc_solid)
2984 {
2985 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2986 }
2987
2988 if(cmb.type == cSLOPE)
2989 {
2990 slope_info s(cmb, tx, ty);
2991 s.draw(dest, 0, 0, COLOR_SLOPE);
2992 }
2993 }
2994 }
2995 }
2996 }
2997
2998 if(flags&cFLAGS)
2999 {
3000 if(LayerMaskInt[CurrentLayer]!=0)
3001 {
3002 for(int32_t i=0; i<176; i++)
3003 {
3004 if(CurrentLayer==0)
3005 {
3006 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3007 }
3008 else
3009 {
3010 if(prv_mode)
3011 {
3012 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3013 }
3014 else if(basescr->layermap[CurrentLayer-1] > 0)
3015 {
3016 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3017
3018 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3019 {
3020 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3021 TheMaps[_lscr].data[i],
3022 TheMaps[_lscr].cset[i], flags,
3023 TheMaps[_lscr].sflag[i]);
3024 }
3025 }
3026 }
3027 }
3028 }
3029 }
3030
3031 int32_t dark = basescr->flags&cDARK;
3032
3033 if(dark && !(flags&cNODARK)
3034 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3035 {
3036 for(int32_t j=0; j<80; j++)
3037 {
3038 for(int32_t i=0; i<(80)-j; i++)
3039 {
3040 if(((i^j)&1)==0)
3041 {
3042 putpixel(dest,x+i,y+j,vc(blackout_color));
3043 }
3044 }
3045 }
3046 }
3047
3048 if(ShowMisalignments)
3049 {
3050 check_alignments(dest,x,y,screen);
3051 }
3052 }
3053
3054 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3055 {
3056 if(map<0)
3057 map=cursor.map;
3058
3059 if(scr<0)
3060 scr=cursor.screen;
3061
3062 mapscr* layer=AbsoluteScr(map,scr);
3063 int32_t layermap=0, layerscreen=0;
3064
3065 if(!(layer->valid&mVALID))
3066 {
3067 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3068 rectfill(dest,x,y,x+255,y+15,vc(1));
3069 return;
3070 }
3071
3072 int32_t dark = layer->flags&4;
3073
3074 if(LayerMaskInt[0]==0)
3075 {
3076 rectfill(dest,x,y,x+255,y+15,0);
3077 }
3078
3079
3080 for(int32_t k=1; k<3; k++)
3081 {
3082 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3083 {
3084 layermap=layer->layermap[k]-1;
3085
3086 if(layermap>-1 && layermap<map_count)
3087 {
3088 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3089
3090 for(int32_t i=c; i<(c&0xF0)+16; i++)
3091 {
3092 auto data = TheMaps[layerscreen].data[i];
3093 auto cs = TheMaps[layerscreen].cset[i];
3094 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3095 }
3096 }
3097 }
3098 }
3099
3100 if(LayerMaskInt[0]!=0)
3101 {
3102 for(int32_t i=c; i<(c&0xF0)+16; i++)
3103 {
3104 word cmbdat = (i < 176 ? layer->data[i] : 0);
3105 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3106 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3107 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3108 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3109 }
3110 }
3111
3112 for(int32_t k=0; k<2; k++)
3113 {
3114 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3115 {
3116 layermap=layer->layermap[k]-1;
3117
3118 if(layermap>-1 && layermap<map_count)
3119 {
3120 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3121
3122 for(int32_t i=c; i<(c&0xF0)+16; i++)
3123 {
3124 auto data = TheMaps[layerscreen].data[i];
3125 auto cs = TheMaps[layerscreen].cset[i];
3126 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3127 }
3128 }
3129 }
3130 }
3131
3132 int32_t doortype[4];
3133
3134 for(int32_t i=0; i<4; i++)
3135 {
3136 switch(layer->door[i])
3137 {
3138 case dOPEN:
3139 doortype[i]=dt_pass;
3140 break;
3141
3142 case dLOCKED:
3143 doortype[i]=dt_lock;
3144 break;
3145
3146 case d1WAYSHUTTER:
3147 case dSHUTTER:
3148 doortype[i]=dt_shut;
3149 break;
3150
3151 case dBOSS:
3152 doortype[i]=dt_boss;
3153 break;
3154
3155 case dBOMB:
3156 doortype[i]=dt_bomb;
3157 break;
3158 }
3159 }
3160
3161 if(c<16)
3162 {
3163 switch(layer->door[up])
3164 {
3165 case dBOMB:
3166 case dOPEN:
3167 case dLOCKED:
3168 case d1WAYSHUTTER:
3169 case dSHUTTER:
3170 case dBOSS:
3171 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3172 break;
3173 }
3174 }
3175 else if(c>159)
3176 {
3177 switch(layer->door[down])
3178 {
3179 case dBOMB:
3180 case dOPEN:
3181 case dLOCKED:
3182 case d1WAYSHUTTER:
3183 case dSHUTTER:
3184 case dBOSS:
3185 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3186 break;
3187 }
3188 }
3189
3190 for(int32_t k=2; k<4; k++)
3191 {
3192 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3193 {
3194 layermap=layer->layermap[k]-1;
3195
3196 if(layermap>-1 && layermap<map_count)
3197 {
3198 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3199
3200 for(int32_t i=c; i<(c&0xF0)+16; i++)
3201 {
3202 if(layer->layeropacity[k]<255)
3203 {
3204 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3205 }
3206 else
3207 {
3208 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3209 }
3210 }
3211 }
3212 }
3213 }
3214
3215 //Overhead L0
3216 if(LayerMaskInt[0]!=0)
3217 {
3218 for(int32_t i=c; i<(c&0xF0)+16; i++)
3219 {
3220 int32_t ct1=layer->data[i];
3221 int32_t ct3=combobuf[ct1].type;
3222
3223 if(combo_class_buf[ct3].overhead)
3224 {
3225 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3226 }
3227 }
3228 }
3229
3230 //Overhead L1/2
3231 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3232 {
3233 for(int32_t k = 0; k < 2; ++k)
3234 {
3235 if(LayerMaskInt[k+1]!=0)
3236 {
3237 layermap=layer->layermap[k]-1;
3238
3239 if(layermap>-1 && layermap<map_count)
3240 {
3241 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3242 for(int32_t i=c; i<(c&0xF0)+16; i++)
3243 {
3244 auto data = TheMaps[layerscreen].data[i];
3245 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3246 auto cs = TheMaps[layerscreen].cset[i];
3247 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3248 }
3249 }
3250 }
3251 }
3252 }
3253
3254 for(int32_t k=4; k<6; k++)
3255 {
3256 if(LayerMaskInt[k+1]!=0)
3257 {
3258 layermap=layer->layermap[k]-1;
3259
3260 if(layermap>-1 && layermap<map_count)
3261 {
3262 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3263
3264 for(int32_t i=c; i<(c&0xF0)+16; i++)
3265 {
3266 auto data = TheMaps[layerscreen].data[i];
3267 auto cs = TheMaps[layerscreen].cset[i];
3268 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3269 }
3270 }
3271 }
3272 }
3273
3274 if(flags&cWALK)
3275 {
3276 if(LayerMaskInt[0]!=0)
3277 {
3278 for(int32_t i=c; i<(c&0xF0)+16; i++)
3279 {
3280 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3281 }
3282 }
3283
3284 for(int32_t k=0; k<2; k++)
3285 {
3286 if(LayerMaskInt[k+1]!=0)
3287 {
3288 for(int32_t i=c; i<(c&0xF0)+16; i++)
3289 {
3290 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3291 }
3292 }
3293 }
3294 }
3295
3296 if(flags&cFLAGS)
3297 {
3298 if(LayerMaskInt[CurrentLayer]!=0)
3299 {
3300 for(int32_t i=c; i<(c&0xF0)+16; i++)
3301 {
3302 if(CurrentLayer==0)
3303 {
3304 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3305 }
3306 else
3307 {
3308 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3309
3310 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3311 {
3312 if(i < 176)
3313 {
3314 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3315 TheMaps[_lscr].data[i],
3316 TheMaps[_lscr].cset[i], flags|dark,
3317 TheMaps[_lscr].sflag[i]);
3318 }
3319 else
3320 {
3321 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3322 }
3323 }
3324 }
3325 }
3326 }
3327
3328 /*
3329 if (LayerMaskInt[0]!=0) {
3330 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3331 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3332 }
3333 }
3334 */
3335 }
3336
3337 if(ShowMisalignments)
3338 {
3339 if(c<16)
3340 {
3341 check_alignments(dest,x,y,scr);
3342 }
3343 else if(c>159)
3344 {
3345 check_alignments(dest,x,y-160,scr);
3346 }
3347 }
3348 }
3349
3350 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3351 {
3352 if(map<0)
3353 map=cursor.map;
3354
3355 if(scr<0)
3356 scr=cursor.screen;
3357
3358 mapscr* layer=AbsoluteScr(map,scr);
3359 int32_t layermap=0, layerscreen=0;
3360
3361 if(!(layer->valid&mVALID))
3362 {
3363 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3364 rectfill(dest,x,y,x+15,y+175,vc(1));
3365 return;
3366 }
3367
3368 int32_t dark = layer->flags&4;
3369
3370 if(LayerMaskInt[0]==0)
3371 {
3372 rectfill(dest,x,y,x+15,y+175,0);
3373 }
3374
3375
3376 for(int32_t k=1; k<3; k++)
3377 {
3378 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3379 {
3380 layermap=layer->layermap[k]-1;
3381
3382 if(layermap>-1 && layermap<map_count)
3383 {
3384 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3385
3386 for(int32_t i=c; i<176; i+=16)
3387 {
3388 auto data = TheMaps[layerscreen].data[i];
3389 auto cs = TheMaps[layerscreen].cset[i];
3390 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3391 }
3392 }
3393 }
3394 }
3395
3396 if(LayerMaskInt[0]!=0)
3397 {
3398 for(int32_t i=c; i<176; i+=16)
3399 {
3400 word cmbdat = layer->data[i];
3401 byte cmbcset = layer->cset[i];
3402 int32_t cmbflag = layer->sflag[i];
3403 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3404 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3405 }
3406 }
3407
3408 for(int32_t k=0; k<2; k++)
3409 {
3410 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3411 {
3412 layermap=layer->layermap[k]-1;
3413
3414 if(layermap>-1 && layermap<map_count)
3415 {
3416 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3417
3418 for(int32_t i=c; i<176; i+=16)
3419 {
3420 auto data = TheMaps[layerscreen].data[i];
3421 auto cs = TheMaps[layerscreen].cset[i];
3422 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3423 }
3424 }
3425 }
3426 }
3427
3428 int32_t doortype[4];
3429
3430 for(int32_t i=0; i<4; i++)
3431 {
3432 switch(layer->door[i])
3433 {
3434 case dOPEN:
3435 doortype[i]=dt_pass;
3436 break;
3437
3438 case dLOCKED:
3439 doortype[i]=dt_lock;
3440 break;
3441
3442 case d1WAYSHUTTER:
3443 case dSHUTTER:
3444 doortype[i]=dt_shut;
3445 break;
3446
3447 case dBOSS:
3448 doortype[i]=dt_boss;
3449 break;
3450
3451 case dBOMB:
3452 doortype[i]=dt_bomb;
3453 break;
3454 }
3455 }
3456
3457 if((c&0x0F)==0)
3458 {
3459 switch(layer->door[left])
3460 {
3461
3462 case dBOMB:
3463 case dOPEN:
3464 case dLOCKED:
3465 case d1WAYSHUTTER:
3466 case dSHUTTER:
3467 case dBOSS:
3468 // put_door(dest,64,left,doortype[left],x+256,y,true);
3469 put_door(dest,64,left,doortype[left],x,y,true,scr);
3470 break;
3471 }
3472 }
3473 else if((c&0x0F)==15)
3474 {
3475 switch(layer->door[right])
3476 {
3477 case dBOMB:
3478 case dOPEN:
3479 case dLOCKED:
3480 case d1WAYSHUTTER:
3481 case dSHUTTER:
3482 case dBOSS:
3483 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3484 break;
3485 }
3486 }
3487
3488 for(int32_t k=2; k<4; k++)
3489 {
3490 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3491 {
3492 layermap=layer->layermap[k]-1;
3493
3494 if(layermap>-1 && layermap<map_count)
3495 {
3496 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3497
3498 for(int32_t i=c; i<176; i+=16)
3499 {
3500 auto data = TheMaps[layerscreen].data[i];
3501 auto cs = TheMaps[layerscreen].cset[i];
3502 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3503 }
3504 }
3505 }
3506 }
3507
3508 //Overhead L0
3509 if(LayerMaskInt[0]!=0)
3510 {
3511 for(int32_t i=c; i<176; i+=16)
3512 {
3513 auto data = TheMaps[layerscreen].data[i];
3514 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3515 auto cs = TheMaps[layerscreen].cset[i];
3516 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3517 }
3518 }
3519 //Overhead L1/2
3520 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3521 {
3522 for(int32_t k = 0; k < 2; ++k)
3523 {
3524 if(LayerMaskInt[k+1]!=0)
3525 {
3526 layermap=layer->layermap[k]-1;
3527
3528 if(layermap>-1 && layermap<map_count)
3529 {
3530 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3531 for(int32_t i=c; i<176; i+=16)
3532 {
3533 auto data = TheMaps[layerscreen].data[i];
3534 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3535 auto cs = TheMaps[layerscreen].cset[i];
3536 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3537 }
3538 }
3539 }
3540 }
3541 }
3542
3543
3544 for(int32_t k=4; k<6; k++)
3545 {
3546 if(LayerMaskInt[k+1]!=0)
3547 {
3548 layermap=layer->layermap[k]-1;
3549
3550 if(layermap>-1 && layermap<map_count)
3551 {
3552 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3553
3554 for(int32_t i=c; i<176; i+=16)
3555 {
3556 auto data = TheMaps[layerscreen].data[i];
3557 auto cs = TheMaps[layerscreen].cset[i];
3558 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3559 }
3560 }
3561 }
3562 }
3563
3564 if(flags&cWALK)
3565 {
3566 if(LayerMaskInt[0]!=0)
3567 {
3568 for(int32_t i=c&0xF; i<176; i+=16)
3569 {
3570 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3571 }
3572 }
3573
3574 for(int32_t k=0; k<2; k++)
3575 {
3576 if(LayerMaskInt[k+1]!=0)
3577 {
3578 for(int32_t i=c&0xF; i<176; i+=16)
3579 {
3580 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3581 }
3582 }
3583 }
3584 }
3585
3586 if(flags&cFLAGS)
3587 {
3588 if(LayerMaskInt[CurrentLayer]!=0)
3589 {
3590 for(int32_t i=c; i<176; i+=16)
3591 {
3592 if(CurrentLayer==0)
3593 {
3594 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3595 }
3596 else
3597 {
3598 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3599
3600 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3601 {
3602 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3603 TheMaps[_lscr].data[i],
3604 TheMaps[_lscr].cset[i], flags|dark,
3605 TheMaps[_lscr].sflag[i]);
3606 }
3607 }
3608 }
3609 }
3610 }
3611
3612 if(ShowMisalignments)
3613 {
3614 if((c&0x0F)==0)
3615 {
3616 check_alignments(dest,x,y,scr);
3617 }
3618 else if((c&0x0F)==15)
3619 {
3620 check_alignments(dest,x-240,y,scr);
3621 }
3622 }
3623 }
3624
3625 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3626 {
3627 if(map<0)
3628 map=cursor.map;
3629
3630 if(scr<0)
3631 scr=cursor.screen;
3632
3633 mapscr* layer=AbsoluteScr(map,scr);
3634 int32_t layermap=0, layerscreen=0;
3635
3636 if(!(layer->valid&mVALID))
3637 {
3638 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3639 rectfill(dest,x,y,x+15,y+15,vc(1));
3640 return;
3641 }
3642
3643 int32_t dark = layer->flags&4;
3644
3645 if(LayerMaskInt[0]!=0)
3646 {
3647 rectfill(dest,x,y,x+15,y+15,0);
3648 }
3649
3650 for(int32_t k=1; k<3; k++)
3651 {
3652 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3653 {
3654 layermap=layer->layermap[k]-1;
3655
3656 if(layermap>-1 && layermap<map_count)
3657 {
3658 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3659
3660 auto data = TheMaps[layerscreen].data[c];
3661 auto cs = TheMaps[layerscreen].cset[c];
3662 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3663 }
3664 }
3665 }
3666
3667 if(LayerMaskInt[0]!=0)
3668 {
3669 word cmbdat = layer->data[c];
3670 byte cmbcset = layer->cset[c];
3671 int32_t cmbflag = layer->sflag[c];
3672 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3673 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3674 }
3675
3676
3677 for(int32_t k=0; k<2; k++)
3678 {
3679 if(LayerMaskInt[k+1]!=0)
3680 {
3681 layermap=layer->layermap[k]-1;
3682
3683 if(layermap>-1 && layermap<map_count)
3684 {
3685 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3686
3687 auto data = TheMaps[layerscreen].data[c];
3688 auto cs = TheMaps[layerscreen].cset[c];
3689 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3690 }
3691 }
3692 }
3693
3694 for(int32_t k=2; k<4; k++)
3695 {
3696 if(LayerMaskInt[k+1]!=0)
3697 {
3698 layermap=layer->layermap[k]-1;
3699
3700 if(layermap>-1 && layermap<map_count)
3701 {
3702 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3703 auto data = TheMaps[layerscreen].data[c];
3704 auto cs = TheMaps[layerscreen].cset[c];
3705 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3706 }
3707 }
3708 }
3709
3710 //Overhead L0
3711 if(LayerMaskInt[0]!=0)
3712 {
3713 auto data = TheMaps[layerscreen].data[c];
3714 if(combo_class_buf[combobuf[data].type].overhead)
3715 {
3716 auto cs = TheMaps[layerscreen].cset[c];
3717 drawcombo(dest,x,y,data,cs,0,0);
3718 }
3719 }
3720 //Overhead L1/2
3721 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3722 {
3723 for(int32_t k = 0; k < 2; ++k)
3724 {
3725 if(LayerMaskInt[k+1]!=0)
3726 {
3727 layermap=layer->layermap[k]-1;
3728
3729 if(layermap>-1 && layermap<map_count)
3730 {
3731 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3732 auto data = TheMaps[layerscreen].data[c];
3733 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3734 auto cs = TheMaps[layerscreen].cset[c];
3735 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3736 }
3737 }
3738 }
3739 }
3740
3741
3742 for(int32_t k=4; k<6; k++)
3743 {
3744 if(LayerMaskInt[k+1]!=0)
3745 {
3746 layermap=layer->layermap[k]-1;
3747
3748 if(layermap>-1 && layermap<map_count)
3749 {
3750 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3751 auto data = TheMaps[layerscreen].data[c];
3752 auto cs = TheMaps[layerscreen].cset[c];
3753 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3754 }
3755 }
3756 }
3757
3758 if(flags&cWALK)
3759 {
3760 if(LayerMaskInt[0]!=0)
3761 {
3762 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3763 }
3764
3765 for(int32_t k=0; k<2; k++)
3766 {
3767 if(LayerMaskInt[k+1]!=0)
3768 {
3769 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3770 }
3771 }
3772 }
3773
3774 if(flags&cFLAGS)
3775 {
3776 if(LayerMaskInt[CurrentLayer]!=0)
3777 {
3778 int32_t i = c;
3779 //for(int32_t i=c; i==c; i++)
3780 {
3781 if(CurrentLayer==0)
3782 {
3783 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3784 }
3785 else
3786 {
3787 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3788
3789 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3790 {
3791 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3792 TheMaps[_lscr].data[i],
3793 TheMaps[_lscr].cset[i], flags|dark,
3794 TheMaps[_lscr].sflag[i]);
3795 }
3796 }
3797 }
3798 }
3799 }
3800
3801 if(ShowMisalignments)
3802 {
3803 switch(c)
3804 {
3805 case 0:
3806 check_alignments(dest,x,y,scr);
3807 break;
3808
3809 case 15:
3810 check_alignments(dest,x-240,y,scr);
3811 break;
3812
3813 case 160:
3814 check_alignments(dest,x,y-160,scr);
3815 break;
3816
3817 case 175:
3818 check_alignments(dest,x-240,y-160,scr);
3819 break;
3820 }
3821 }
3822 }
3823
3824 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3825 {
3826 if (InvalidBG == 2)
3827 {
3828 draw_checkerboard(dest, x, y, 16);
3829 }
3830 else if(InvalidBG == 1)
3831 {
3832 for(int32_t dy=0; dy<16; dy++)
3833 {
3834 for(int32_t dx=0; dx<16; dx++)
3835 {
3836 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3837 }
3838 }
3839 }
3840 else
3841 {
3842 rectfill(dest, x, y, x+15, y+15, vc(0));
3843 rect(dest, x, y, x+15, y+15, vc(15));
3844 line(dest, x, y, x+15, y+15, vc(15));
3845 line(dest, x, y+15, x+15, y, vc(15));
3846 }
3847 }
3848
3849 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3850 {
3851 if (InvalidBG == 2)
3852 {
3853 for(int32_t q = 0; q < 11; ++q)
3854 draw_checkerboard(dest, x, y + q * 16, 16);
3855 }
3856 else if(InvalidBG == 1)
3857 {
3858 for(int32_t dy=0; dy<176; dy++)
3859 {
3860 for(int32_t dx=0; dx<16; dx++)
3861 {
3862 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3863 }
3864 }
3865 }
3866 else
3867 {
3868 rectfill(dest, x, y, x+15, y+175, vc(0));
3869 rect(dest, x, y, x+15, y+175, vc(15));
3870 line(dest, x, y, x+15, y+175, vc(15));
3871 line(dest, x, y+175, x+15, y, vc(15));
3872 }
3873 }
3874
3875 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3876 {
3877 if (InvalidBG == 2)
3878 {
3879 for (int32_t q = 0; q < 16; ++q)
3880 draw_checkerboard(dest, x + q * 16, y, 16);
3881 }
3882 else if(InvalidBG == 1)
3883 {
3884 for(int32_t dy=0; dy<16; dy++)
3885 {
3886 for(int32_t dx=0; dx<256; dx++)
3887 {
3888 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3889 }
3890 }
3891 }
3892 else
3893 {
3894 rectfill(dest, x, y, x+255, y+15, vc(0));
3895 rect(dest, x, y, x+255, y+15, vc(15));
3896 line(dest, x, y, x+255, y+15, vc(15));
3897 line(dest, x, y+15, x+255, y, vc(15));
3898 }
3899 }
3900
3901 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3902 {
3903 for(int32_t i=0; i<176; i++)
3904 {
3905 word cmbdat = screens[TEMPLATE].data[i];
3906 byte cmbcset = screens[TEMPLATE].cset[i];
3907 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3908 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3909 }
3910 }
3911
3912 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3913 {
3914 for(int32_t i=0; i<176; i++)
3915 {
3916 word cmbdat = screens[TEMPLATE2].data[i];
3917 byte cmbcset = screens[TEMPLATE2].cset[i];
3918 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3919 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3920 }
3921 }
3922
3923 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3924 {
3925 word cmbdat = screens[TEMPLATE].data[pos];
3926 byte cmbcset = screens[TEMPLATE].cset[pos];
3927 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3928 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3929 }
3930
3931 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3932 {
3933 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3934 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3935 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3936 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3937 }
3938
3939 void zmap::scroll(int32_t dir, bool warp)
3940 {
3941 if(cursor.map<map_count)
3942 {
3943 switch(dir)
3944 {
3945 case up:
3946 if(warp && Map.CurrScr()->flags2&wfUP)
3947 {
3948 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3949 }
3950 else if(cursor.screen>15)
3951 {
3952 setCurrScr(cursor.screen - 16);
3953 }
3954
3955 break;
3956
3957 case down:
3958 if(warp && Map.CurrScr()->flags2&wfDOWN)
3959 {
3960 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3961 }
3962 else if(cursor.screen<MAPSCRS-16)
3963 {
3964 setCurrScr(cursor.screen + 16);
3965 }
3966
3967 break;
3968
3969 case left:
3970 if(warp && Map.CurrScr()->flags2&wfLEFT)
3971 {
3972 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3973 }
3974 else if(cursor.screen&15)
3975 {
3976 setCurrScr(cursor.screen - 1);
3977 }
3978
3979 break;
3980
3981 case right:
3982 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3983 {
3984 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3985 }
3986 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3987 {
3988 setCurrScr(cursor.screen + 1);
3989 }
3990
3991 break;
3992 }
3993 }
3994 }
3995
3996 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3997 {
3998 switch(side)
3999 {
4000 case up:
4001 switch(door)
4002 {
4003 case dWALL:
4004 case dBOMB:
4005 case dWALK:
4006 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4007 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4008 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4009 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4010 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4011 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4012 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4013 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4014 break;
4015
4016 default:
4017 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4018 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4019 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4020 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4021 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4022 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4023 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4024 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4025 break;
4026 }
4027
4028 break;
4029
4030 case down:
4031 switch(door)
4032 {
4033 case dWALL:
4034 case dBOMB:
4035 case dWALK:
4036 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4037 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4038 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4039 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4040 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4041 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4042 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4043 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4044 break;
4045
4046 default:
4047 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4048 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4049 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4050 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4051 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4052 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4053 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4054 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4055 break;
4056 }
4057
4058 break;
4059
4060 case left:
4061 switch(door)
4062 {
4063 case dWALL:
4064 case dBOMB:
4065 case dWALK:
4066 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4067 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4068 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4069 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4070 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4071 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4072 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4073 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4074 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4075 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4076 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4077 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4078 break;
4079
4080 default:
4081 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4082 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4083 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4084 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4085 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4086 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4087 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4088 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4089 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4090 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4091 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4092 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4093 break;
4094 }
4095
4096 break;
4097
4098 case right:
4099 switch(door)
4100 {
4101 case dWALL:
4102 case dBOMB:
4103 case dWALK:
4104 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4105 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4106 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4107 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4108 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4109 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4110 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4111 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4112 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4113 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4114 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4115 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4116 break;
4117
4118 default:
4119 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4120 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4121 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4122 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4123 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4124 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4125 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4126 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4127 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4128 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4129 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4130 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4131 break;
4132 }
4133
4134 break;
4135 }
4136 }
4137 void zmap::DoPutDoorCommand(int side, int door, bool force)
4138 {
4139 if(!force && screens[cursor.screen].door[side] == door)
4140 return;
4141 bool already_list = InListCommand();
4142 if(!already_list)
4143 StartListCommand();
4144 DoSetDoorCommand(cursor.screen,side,door);
4145 if(door != dNONE)
4146 {
4147 word data[176] = {0};
4148 byte cset[176] = {0};
4149 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4150 for(int q = 0; q < 176; ++q)
4151 if(data[q])
4152 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4153 }
4154 if(!already_list)
4155 FinishListCommand();
4156 }
4157 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4158 {
4159 if(screens[screen].door[side] == door)
4160 return;
4161
4162 screens[screen].door[side] = door;
4163 if(door != dNONE)
4164 {
4165 word data[176] = {0};
4166 byte cset[176] = {0};
4167 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4168 for(int q = 0; q < 176; ++q)
4169 if(data[q])
4170 {
4171 screens[screen].data[q] = data[q];
4172 screens[screen].cset[q] = cset[q];
4173 }
4174 }
4175 }
4176
4177 void list_command::execute()
4178 {
4179 for (auto command : commands)
4180 {
4181 command->execute();
4182 }
4183 }
4184
4185 void list_command::undo()
4186 {
4187 for (int i = commands.size() - 1; i >= 0; i--)
4188 {
4189 commands[i]->undo();
4190 }
4191 }
4192
4193 int list_command::size()
4194 {
4195 int s = 0;
4196 for (auto command : commands)
4197 {
4198 s += command->size();
4199 }
4200 return s;
4201 }
4202
4203 void set_combo_command::execute()
4204 {
4205 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4206 if (!scr_ptr) return;
4207
4208 if (combo != -1) scr_ptr->data[pos] = combo;
4209 scr_ptr->cset[pos] = cset;
4210 }
4211
4212 void set_combo_command::undo()
4213 {
4214 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4215 if(!mapscr_ptr) return;
4216 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4217 mapscr_ptr->cset[pos] = prev_cset;
4218 }
4219
4220 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4221 {
4222 std::array<int, 8> initd_arr;
4223 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4224
4225 return {
4226 .x = ffc.x,
4227 .y = ffc.y,
4228 .vx = ffc.vx,
4229 .vy = ffc.vy,
4230 .ax = ffc.ax,
4231 .ay = ffc.ay,
4232 .data = ffc.data,
4233 .cset = ffc.cset,
4234 .delay = ffc.delay,
4235 .link = ffc.link,
4236 .script = ffc.script,
4237 .tw = ffc.txsz,
4238 .th = ffc.tysz,
4239 .ew = ffc.hit_width,
4240 .eh = ffc.hit_height,
4241 .flags = ffc.flags,
4242 .initd = initd_arr,
4243 .layer = ffc.layer
4244 };
4245 }
4246
4247 void set_ffc_command::execute()
4248 {
4249 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4250 if(!mapscr_ptr) return;
4251
4252 mapscr_ptr->valid |= mVALID;
4253 mapscr_ptr->ffcs[i].x = data.x;
4254 mapscr_ptr->ffcs[i].y = data.y;
4255 mapscr_ptr->ffcs[i].vx = data.vx;
4256 mapscr_ptr->ffcs[i].vy = data.vy;
4257 mapscr_ptr->ffcs[i].ax = data.ax;
4258 mapscr_ptr->ffcs[i].ay = data.ay;
4259 mapscr_ptr->ffcs[i].data = data.data;
4260 mapscr_ptr->ffcs[i].cset = data.cset;
4261 mapscr_ptr->ffcs[i].delay = data.delay;
4262 mapscr_ptr->ffcs[i].link = data.link;
4263 mapscr_ptr->ffcs[i].script = data.script;
4264 mapscr_ptr->ffcs[i].flags = data.flags;
4265 mapscr_ptr->ffEffectWidth(i, data.ew);
4266 mapscr_ptr->ffEffectHeight(i, data.eh);
4267 mapscr_ptr->ffTileWidth(i, data.tw);
4268 mapscr_ptr->ffTileHeight(i, data.th);
4269 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4270 mapscr_ptr->ffcs[i].layer = data.layer;
4271 mapscr_ptr->ffcCountMarkDirty();
4272 mapscr_ptr->ffcs[i].updateSolid();
4273 }
4274
4275 void set_ffc_command::undo()
4276 {
4277 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4278 if(!mapscr_ptr) return;
4279
4280 mapscr_ptr->ffcs[i].x = prev_data.x;
4281 mapscr_ptr->ffcs[i].y = prev_data.y;
4282 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4283 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4284 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4285 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4286 mapscr_ptr->ffcs[i].data = prev_data.data;
4287 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4288 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4289 mapscr_ptr->ffcs[i].link = prev_data.link;
4290 mapscr_ptr->ffcs[i].script = prev_data.script;
4291 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4292 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4293 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4294 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4295 mapscr_ptr->ffTileHeight(i, prev_data.th);
4296 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4297 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4298 mapscr_ptr->ffcCountMarkDirty();
4299 mapscr_ptr->ffcs[i].updateSolid();
4300 }
4301
4302 void set_flag_command::execute()
4303 {
4304 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4305 if(!mapscr_ptr) return;
4306
4307 mapscr_ptr->valid |= mVALID;
4308 mapscr_ptr->sflag[pos] = flag;
4309 }
4310
4311 void set_flag_command::undo()
4312 {
4313 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4314 if(!mapscr_ptr) return;
4315 mapscr_ptr->sflag[pos] = prev_flag;
4316 }
4317
4318 void set_door_command::execute()
4319 {
4320 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4321 if(!mapscr_ptr) return;
4322
4323 mapscr_ptr->valid |= mVALID;
4324 mapscr_ptr->door[side] = door;
4325 }
4326
4327 void set_door_command::undo()
4328 {
4329 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4330 }
4331
4332 void set_dcs_command::execute()
4333 {
4334 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4335 if(!mapscr_ptr) return;
4336
4337 mapscr_ptr->valid |= mVALID;
4338 mapscr_ptr->door_combo_set = dcs;
4339 }
4340
4341 void set_dcs_command::undo()
4342 {
4343 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4344 }
4345
4346 void paste_screen_command::execute()
4347 {
4348 perform(screen.get());
4349 }
4350
4351 void paste_screen_command::undo()
4352 {
4353 if (prev_screens.size() > 1)
4354 {
4355 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4356 ASSERT(prev_screens.size() == 128);
4357 for (int i = 0; i < 128; i++)
4358 {
4359 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4360 // TODO: why not just this?
4361 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4362 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4363 }
4364 return;
4365 }
4366
4367 perform(prev_screens[0].get());
4368 }
4369
4370 int paste_screen_command::size()
4371 {
4372 return prev_screens.size() + 1;
4373 }
4374
4375 void paste_screen_command::perform(mapscr* to)
4376 {
4377 if (to)
4378 {
4379 switch (type) {
4380 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4381 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4382 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4383 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4384 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4385 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4386 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4387 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4388 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4389 case ScreenPartial: Map.Paste(*to, screen_index); break;
4390 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4391 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4392 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4393 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4394 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4395 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4396 }
4397 }
4398 else
4399 {
4400 Map.clearscr(screen_index);
4401 }
4402 refresh(rALL);
4403 }
4404
4405 void set_screen_command::execute()
4406 {
4407 if (screen)
4408 {
4409 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4410 }
4411 else
4412 {
4413 Map.clearscr(screen_index);
4414 }
4415 refresh(rALL);
4416 }
4417
4418 void set_screen_command::undo()
4419 {
4420 if (prev_screen)
4421 {
4422 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4423 }
4424 else
4425 {
4426 Map.clearscr(screen_index);
4427 }
4428 refresh(rALL);
4429 }
4430
4431 int set_screen_command::size()
4432 {
4433 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4434 }
4435
4436 static std::shared_ptr<list_command> current_list_command;
4437 void zmap::StartListCommand()
4438 {
4439 ASSERT(!current_list_command);
4440 current_list_command.reset(new list_command);
4441 }
4442
4443 void zmap::FinishListCommand()
4444 {
4445 if (current_list_command->commands.size() == 1)
4446 {
4447 undo_stack.push_back(current_list_command->commands[0]);
4448 }
4449 else if (current_list_command->commands.size() > 1)
4450 {
4451 undo_stack.push_back(current_list_command);
4452 }
4453 CapCommandHistory();
4454 current_list_command = nullptr;
4455 }
4456
4457 void zmap::RevokeListCommand()
4458 {
4459 current_list_command->undo();
4460 current_list_command = nullptr;
4461 }
4462
4463 bool zmap::InListCommand() const
4464 {
4465 return current_list_command ? true : false;
4466 }
4467
4468 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4469 {
4470 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4471 if (!skip_execute) command->execute();
4472 if (current_list_command)
4473 {
4474 current_list_command->commands.push_back(command);
4475 if (current_list_command->commands.size() == 1)
4476 {
4477 current_list_command->cursor = command->cursor;
4478 }
4479 }
4480 else
4481 {
4482 undo_stack.push_back(command);
4483 CapCommandHistory();
4484 }
4485 saved = false;
4486 }
4487
4488 void zmap::UndoCommand()
4489 {
4490 if (undo_stack.size() <= 0) return;
4491
4492 // If not currently looking at the associated screen, first change the view
4493 // and wait for the next call to actually undo this command.
4494 auto command = undo_stack.back();
4495 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4496 {
4497 setCursor(command.get()->cursor);
4498 return;
4499 }
4500
4501 command->undo();
4502 redo_stack.push(command);
4503 undo_stack.pop_back();
4504 saved = false;
4505 }
4506
4507 void zmap::RedoCommand()
4508 {
4509 if (redo_stack.size() <= 0) return;
4510
4511 // If not currently selected the associated screen, first change the cursor
4512 // and wait for the next call to actually execute this command.
4513 auto command = redo_stack.top();
4514 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4515 {
4516 setCursor(command.get()->cursor);
4517 return;
4518 }
4519
4520 command->execute();
4521 undo_stack.push_back(command);
4522 redo_stack.pop();
4523 saved = false;
4524 }
4525
4526 11 void zmap::ClearCommandHistory()
4527 {
4528 11 current_list_command = nullptr;
4529 11 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4530 11 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4531 11 }
4532
4533 // Extra amount is from mapscr's vectors.
4534 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4535 // Allow the undo system to use roughly 100 MB of memory.
4536 // This doesn't count the memory used by commands that don't store a mapscr,
4537 // but that should be negligible.
4538 12 static int max_command_size = 100e6 / size_of_mapscr;
4539 void zmap::CapCommandHistory()
4540 {
4541 int size;
4542 do
4543 {
4544 size = 0;
4545 for (auto command : undo_stack)
4546 {
4547 size += command->size();
4548 }
4549 if (size > max_command_size) undo_stack.pop_front();
4550 } while (size > max_command_size);
4551 }
4552
4553 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4554 {
4555 if (!pos.is_valid(cursor))
4556 return;
4557
4558 int map = cursor.map;
4559 int screen = cursor.viewscr + pos.screen_offset();
4560 if (!AbsoluteScr(map, screen))
4561 return;
4562
4563 if (CurrentLayer)
4564 {
4565 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4566 map = scr->layermap[CurrentLayer-1]-1;
4567 screen = scr->layerscreen[CurrentLayer-1];
4568 }
4569 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4570 }
4571
4572 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4573 {
4574 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4575 if (!mapscr_ptr) return;
4576
4577 std::shared_ptr<set_combo_command> command(new set_combo_command);
4578 command->cursor = cursor;
4579 command->map = map;
4580 command->scr = scr;
4581 command->pos = pos;
4582 command->combo = combo;
4583 command->cset = cset;
4584 command->prev_combo = mapscr_ptr->data[pos];
4585 command->prev_cset = mapscr_ptr->cset[pos];
4586 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4587 {
4588 // nothing to do...
4589 return;
4590 }
4591
4592 ExecuteCommand(command);
4593 }
4594
4595 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4596 {
4597 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4598 if(!mapscr_ptr) return;
4599
4600 mapscr_ptr->ensureFFC(i);
4601
4602 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4603
4604 std::array<int, 8> initd_arr;
4605 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4606
4607 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4608
4609 command->cursor = cursor;
4610 command->map = map;
4611 command->scr = scr;
4612 command->i = i;
4613 command->data = data;
4614 command->prev_data = prev_data;
4615 if (data == prev_data)
4616 {
4617 // nothing to do...
4618 return;
4619 }
4620
4621 ExecuteCommand(command);
4622 }
4623
4624 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4625 {
4626 if (!pos.is_valid(cursor))
4627 return;
4628
4629 int map = cursor.map;
4630 int screen = cursor.viewscr + pos.screen_offset();
4631 if (!AbsoluteScr(map, screen))
4632 return;
4633
4634 if (CurrentLayer)
4635 {
4636 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4637 map = scr->layermap[CurrentLayer-1]-1;
4638 screen = scr->layerscreen[CurrentLayer-1];
4639 }
4640 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4641 }
4642
4643 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4644 {
4645 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4646 if(!mapscr_ptr) return;
4647
4648 std::shared_ptr<set_flag_command> command(new set_flag_command);
4649 command->cursor = cursor;
4650 command->map = map;
4651 command->scr = scr;
4652 command->pos = pos;
4653 command->flag = flag;
4654 command->prev_flag = mapscr_ptr->sflag[pos];
4655 if (command->flag == command->prev_flag)
4656 {
4657 // nothing to do...
4658 return;
4659 }
4660
4661 ExecuteCommand(command);
4662 }
4663
4664 void zmap::DoSetDoorCommand(int scr, int side, int door)
4665 {
4666 if(screens[scr].door[side] == door)
4667 return;
4668 std::shared_ptr<set_door_command> command(new set_door_command);
4669 command->cursor = cursor;
4670 command->side = side;
4671 command->door = door;
4672 command->prev_door = screens[scr].door[side];
4673
4674 ExecuteCommand(command);
4675 }
4676 void zmap::DoSetDCSCommand(int dcs)
4677 {
4678 if(screens[cursor.screen].door_combo_set == dcs)
4679 return;
4680 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4681 command->cursor = cursor;
4682 command->dcs = dcs;
4683 command->prev_dcs = screens[cursor.screen].door_combo_set;
4684
4685 ExecuteCommand(command);
4686 }
4687
4688 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4689 {
4690 if (screen == -1)
4691 screen = cursor.screen;
4692
4693 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4694 command->cursor = cursor;
4695 command->type = type;
4696 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4697 command->screen_index = screen;
4698
4699 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4700 {
4701 for (int i=0; i < 128; i++)
4702 {
4703 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4704 }
4705 }
4706 else
4707 {
4708 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4709 }
4710
4711 ExecuteCommand(command);
4712 }
4713
4714 void zmap::DoClearScreenCommand(int screen)
4715 {
4716 std::shared_ptr<set_screen_command> command(new set_screen_command);
4717 command->cursor = cursor;
4718 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4719 command->screen = std::shared_ptr<mapscr>(nullptr);
4720 command->screen_index = screen;
4721
4722 ExecuteCommand(command);
4723 }
4724
4725 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4726 {
4727 std::shared_ptr<set_screen_command> command(new set_screen_command);
4728 command->cursor = cursor;
4729 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4730 Template(floorcombo, floorcset, screen);
4731 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4732
4733 ExecuteCommand(command, true);
4734 }
4735
4736 void zmap::Copy(int scr)
4737 {
4738 if(screens[scr].valid&mVALID)
4739 {
4740 copy_mapscr(&copymapscr, &screens[scr]);
4741 //copymapscr=screens[scr];
4742 can_paste=true;
4743 copymap=cursor.map;
4744 copyscr=scr;
4745 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4746 copyffc = -1;
4747 }
4748 }
4749
4750 void zmap::CopyFFC(int32_t screen, int32_t n)
4751 {
4752 if(screens[screen].valid&mVALID)
4753 {
4754 copy_mapscr(&copymapscr, &screens[screen]);
4755 // Can't paste the screen itself
4756 can_paste = false;
4757 copymap=cursor.map;
4758 copyscr=screen;
4759 copyffc = n;
4760 }
4761 }
4762
4763 void zmap::Paste(const mapscr& copymapscr, int screen)
4764 {
4765 if(can_paste)
4766 {
4767 int32_t oldcolor=getcolor();
4768
4769 if(!(screens[screen].valid&mVALID))
4770 {
4771 screens[screen].valid |= mVALID;
4772 screens[screen].color = copymapscr.color;
4773 }
4774
4775 screens[screen].door_combo_set = copymapscr.door_combo_set;
4776
4777 for(int32_t i=0; i<4; i++)
4778 {
4779 screens[screen].door[i]=copymapscr.door[i];
4780 }
4781
4782 for(int32_t i=0; i<176; i++)
4783 {
4784 screens[screen].data[i] = copymapscr.data[i];
4785 screens[screen].cset[i] = copymapscr.cset[i];
4786 screens[screen].sflag[i] = copymapscr.sflag[i];
4787 }
4788
4789 int32_t newcolor=getcolor();
4790 loadlvlpal(newcolor);
4791
4792 if(newcolor!=oldcolor)
4793 {
4794 rebuild_trans_table();
4795 }
4796
4797 saved=false;
4798 }
4799 }
4800
4801 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4802 {
4803 if(can_paste)
4804 {
4805 screens[screen].undercombo = copymapscr.undercombo;
4806 screens[screen].undercset = copymapscr.undercset;
4807 saved=false;
4808 }
4809 }
4810
4811 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4812 {
4813 if(can_paste)
4814 {
4815 for(int32_t i=0; i<128; i++)
4816 {
4817 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4818 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4819 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4820 }
4821
4822 saved=false;
4823 }
4824 }
4825
4826 // TODO const mapscr& copymapscr
4827 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4828 {
4829 if(can_paste)
4830 {
4831 screens[screen].ffcs = copymapscr.ffcs;
4832 screens[screen].ffcCountMarkDirty();
4833 saved=false;
4834 }
4835 }
4836
4837 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4838 {
4839 if(can_paste)
4840 {
4841 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4842
4843 for(int32_t i=0; i<4; i++)
4844 {
4845 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4846 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4847 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4848 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4849 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4850 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4851 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4852 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4853 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4854 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4855 }
4856
4857 saved=false;
4858 }
4859 }
4860
4861 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4862 {
4863 if(can_paste)
4864 {
4865 screens[screen].csensitive = copymapscr.csensitive;
4866 screens[screen].oceansfx = copymapscr.oceansfx;
4867 screens[screen].bosssfx = copymapscr.bosssfx;
4868 screens[screen].secretsfx = copymapscr.secretsfx;
4869 screens[screen].holdupsfx = copymapscr.holdupsfx;
4870 screens[screen].flags = copymapscr.flags;
4871 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4872 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4873 screens[screen].flags3 = copymapscr.flags3;
4874 screens[screen].flags4 = copymapscr.flags4;
4875 screens[screen].flags5 = copymapscr.flags5;
4876 screens[screen].flags6 = copymapscr.flags6;
4877 screens[screen].flags7 = copymapscr.flags7;
4878 screens[screen].flags8 = copymapscr.flags8;
4879 screens[screen].flags9 = copymapscr.flags9;
4880 screens[screen].flags10 = copymapscr.flags10;
4881 screens[screen].flags11 = copymapscr.flags11;
4882 screens[screen].item = copymapscr.item;
4883 screens[screen].hasitem = copymapscr.hasitem;
4884 screens[screen].itemx = copymapscr.itemx;
4885 screens[screen].itemy = copymapscr.itemy;
4886 screens[screen].nextmap = copymapscr.nextmap;
4887 screens[screen].nextscr = copymapscr.nextscr;
4888 screens[screen].nocarry = copymapscr.nocarry;
4889 screens[screen].noreset = copymapscr.noreset;
4890 screens[screen].exstate_reset = copymapscr.exstate_reset;
4891 screens[screen].exstate_carry = copymapscr.exstate_carry;
4892 screens[screen].path[0] = copymapscr.path[0];
4893 screens[screen].path[1] = copymapscr.path[1];
4894 screens[screen].path[2] = copymapscr.path[2];
4895 screens[screen].path[3] = copymapscr.path[3];
4896 screens[screen].pattern = copymapscr.pattern;
4897 screens[screen].exitdir = copymapscr.exitdir;
4898 screens[screen].screen_midi = copymapscr.screen_midi;
4899 screens[screen].stairx = copymapscr.stairx;
4900 screens[screen].stairy = copymapscr.stairy;
4901 screens[screen].timedwarptics = copymapscr.timedwarptics;
4902 saved=false;
4903 }
4904 }
4905
4906 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4907 {
4908 if(can_paste)
4909 {
4910 screens[screen].warpreturnc = copymapscr.warpreturnc;
4911 screens[screen].warparrivalx = copymapscr.warparrivalx;
4912 screens[screen].warparrivaly = copymapscr.warparrivaly;
4913
4914 for(int32_t i=0; i<4; i++)
4915 {
4916 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4917 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4918 }
4919
4920 saved=false;
4921 }
4922 }
4923
4924 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4925 {
4926 if(can_paste)
4927 {
4928 for(int32_t i=0; i<4; i++)
4929 screens[screen].door[i] = copymapscr.door[i];
4930
4931 screens[screen].door_combo_set = copymapscr.door_combo_set;
4932 saved=false;
4933 }
4934 }
4935
4936 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4937 {
4938 if(can_paste)
4939 {
4940 for(int32_t i=0; i<6; i++)
4941 {
4942 screens[screen].layermap[i] = copymapscr.layermap[i];
4943 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4944 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4945 }
4946
4947 saved=false;
4948 }
4949 }
4950
4951 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4952 {
4953 if(can_paste)
4954 {
4955 screens[screen].room = copymapscr.room;
4956 screens[screen].catchall = copymapscr.catchall;
4957 saved=false;
4958 }
4959 }
4960
4961 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4962 {
4963 if(can_paste)
4964 {
4965 screens[screen].guy = copymapscr.guy;
4966 screens[screen].guytile = copymapscr.guytile;
4967 screens[screen].guycs = copymapscr.guycs;
4968 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4969 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4970 screens[screen].str = copymapscr.str;
4971 saved=false;
4972 }
4973 }
4974
4975 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4976 {
4977 if(can_paste)
4978 {
4979 int32_t oldcolor=getcolor();
4980 screens[screen].color = copymapscr.color;
4981 int32_t newcolor=getcolor();
4982 loadlvlpal(newcolor);
4983
4984 screens[screen].valid|=mVALID;
4985
4986 if(newcolor!=oldcolor)
4987 {
4988 rebuild_trans_table();
4989 }
4990
4991 saved=false;
4992 }
4993 }
4994
4995 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4996 {
4997 if(can_paste)
4998 {
4999 int32_t oldcolor=getcolor();
5000 copy_mapscr(&screens[screen], &copymapscr);
5001 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
5002 //screens[screen]=copymapscr;
5003 int32_t newcolor=getcolor();
5004 loadlvlpal(newcolor);
5005
5006 screens[screen].valid|=mVALID;
5007
5008 if(newcolor!=oldcolor)
5009 {
5010 rebuild_trans_table();
5011 }
5012
5013 saved=false;
5014 }
5015 }
5016
5017
5018 void zmap::PasteToAll(const mapscr& copymapscr)
5019 {
5020 if(can_paste)
5021 {
5022 int32_t oldcolor=getcolor();
5023
5024 for(int32_t x=0; x<128; x++)
5025 {
5026 if(!(screens[x].valid&mVALID))
5027 {
5028 screens[x].valid |= mVALID;
5029 screens[x].color = copymapscr.color;
5030 }
5031
5032 for(int32_t i=0; i<176; i++)
5033 {
5034 screens[x].data[i] = copymapscr.data[i];
5035 screens[x].cset[i] = copymapscr.cset[i];
5036 screens[x].sflag[i] = copymapscr.sflag[i];
5037 }
5038 }
5039
5040 int32_t newcolor=getcolor();
5041 loadlvlpal(newcolor);
5042
5043 if(!(screens[cursor.screen].valid&mVALID))
5044 {
5045 newcolor=-1;
5046 }
5047
5048 if(newcolor!=oldcolor)
5049 {
5050 rebuild_trans_table();
5051 }
5052
5053 saved=false;
5054 }
5055 }
5056
5057 void zmap::PasteAllToAll(const mapscr& copymapscr)
5058 {
5059 if(can_paste)
5060 {
5061 int32_t oldcolor=getcolor();
5062
5063 for(int32_t x=0; x<128; x++)
5064 {
5065 copy_mapscr(&screens[x], &copymapscr);
5066 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5067 //screens[x]=copymapscr;
5068 }
5069
5070 int32_t newcolor=getcolor();
5071 loadlvlpal(newcolor);
5072
5073 if(!(screens[cursor.screen].valid&mVALID))
5074 {
5075 newcolor=-1;
5076 }
5077
5078 if(newcolor!=oldcolor)
5079 {
5080 rebuild_trans_table();
5081 }
5082
5083 saved=false;
5084 }
5085 }
5086
5087 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5088 {
5089 if(can_paste)
5090 {
5091 for(int32_t i=0; i<10; i++)
5092 screens[screen].enemy[i]=copymapscr.enemy[i];
5093 }
5094 }
5095
5096 void zmap::setCopyFFC(int32_t n)
5097 {
5098 copyffc = n;
5099 }
5100
5101 void zmap::update_combo_cycling()
5102 {
5103 if(!prv_mode||!prv_cmbcycle)
5104 {
5105 return;
5106 }
5107
5108 int32_t x;
5109 int32_t newdata[176];
5110 int32_t newcset[176];
5111 bool restartanim[MAXCOMBOS] = {0};
5112
5113 for(int32_t i=0; i<176; i++)
5114 {
5115 newdata[i]=-1;
5116 newcset[i]=-1;
5117
5118 x=prvscr.data[i];
5119
5120 //time to restart
5121 if((combobuf[x].aclk>=combobuf[x].speed) &&
5122 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5123 combobuf[x].can_cycle())
5124 {
5125 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5126 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5127
5128 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5129 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5130 int32_t c = newdata[i];
5131
5132 if(combobuf[c].animflags & AF_CYCLE)
5133 {
5134 restartanim[c]=true;
5135 }
5136 }
5137 }
5138
5139 for(int32_t i=0; i<176; i++)
5140 {
5141 x=prvscr.data[i];
5142
5143 //time to restart
5144 if((combobuf[x].aclk>=combobuf[x].speed) &&
5145 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5146 combobuf[x].can_cycle())
5147 {
5148 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5149 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5150
5151 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5152 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5153 int32_t c = newdata[i];
5154
5155 if(combobuf[c].animflags & AF_CYCLE)
5156 {
5157 restartanim[c]=true;
5158 }
5159 }
5160 }
5161
5162 for(int32_t i=0; i<176; i++)
5163 {
5164 if(newdata[i]==-1)
5165 continue;
5166
5167 prvscr.data[i]=newdata[i];
5168 prvscr.cset[i]=newcset[i];
5169 }
5170
5171 word maxffc = prvscr.numFFC();
5172 for(word i=0; i<maxffc; i++)
5173 {
5174 ffcdata& ffc = prvscr.ffcs[i];
5175 newcombo const& cmb = combobuf[ffc.data];
5176
5177 //time to restart
5178 if((cmb.aclk>=cmb.speed) &&
5179 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5180 cmb.can_cycle())
5181 {
5182 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5183 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5184
5185 if(!(cmb.animflags & AF_CYCLENOCSET))
5186 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5187
5188 if(combobuf[ffc.data].animflags & AF_CYCLE)
5189 {
5190 restartanim[ffc.data]=true;
5191 }
5192 prvscr.ffcs[i].data = ffc.data;
5193 prvscr.ffcs[i].cset=ffc.cset;
5194 }
5195 }
5196
5197
5198 if(get_qr(qr_CMBCYCLELAYERS))
5199 {
5200 for(int32_t j=0; j<6; j++)
5201 {
5202 if(!prvlayers[j].valid)
5203 continue;
5204
5205 for(int32_t i=0; i<176; i++)
5206 {
5207 newdata[i]=-1;
5208 newcset[i]=-1;
5209
5210 x=(prvlayers[j]).data[i];
5211
5212 //time to restart
5213 if((combobuf[x].aclk>=combobuf[x].speed) &&
5214 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5215 combobuf[x].can_cycle())
5216 {
5217 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5218 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5219
5220 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5221 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5222 int32_t c = newdata[i];
5223
5224 if(combobuf[c].animflags & AF_CYCLE)
5225 {
5226 restartanim[c]=true;
5227 }
5228 }
5229 }
5230
5231 for(int32_t i=0; i<176; i++)
5232 {
5233 x=(prvlayers[j]).data[i];
5234
5235 //time to restart
5236 if((combobuf[x].aclk>=combobuf[x].speed) &&
5237 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5238 combobuf[x].can_cycle())
5239 {
5240 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5241 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5242
5243 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5244 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5245 int32_t c = newdata[i];
5246
5247 if(combobuf[c].animflags & AF_CYCLE)
5248 {
5249 restartanim[c]=true;
5250 }
5251 }
5252 }
5253
5254 for(int32_t i=0; i<176; i++)
5255 {
5256 if(newdata[i]==-1)
5257 continue;
5258
5259 prvlayers[j].data[i]=newdata[i];
5260 prvlayers[j].cset[i]=newcset[i];
5261 }
5262 }
5263 }
5264
5265 for(int32_t i=0; i<MAXCOMBOS; i++)
5266 {
5267 if(restartanim[i])
5268 {
5269 combobuf[i].tile = combobuf[i].o_tile;
5270 combobuf[i].cur_frame=0;
5271 combobuf[i].aclk = 0;
5272 }
5273 }
5274 }
5275
5276 void zmap::update_freeform_combos()
5277 {
5278 if(!prv_mode||!prv_cmbcycle)
5279 {
5280 return;
5281 }
5282
5283 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5284 word maxffc = prvscr.numFFC();
5285 for(int32_t i=0; i<maxffc; i++)
5286 {
5287 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5288 {
5289 for(int32_t j=0; j<maxffc; j++)
5290 {
5291 if(i!=j)
5292 {
5293 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5294 {
5295 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5296 {
5297 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5298 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5299 {
5300 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5301 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5302 if(prvscr.ffcs[j].flags&ffc_changethis)
5303 {
5304 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5305 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5306 }
5307
5308 if(prvscr.ffcs[j].flags&ffc_changenext)
5309 prvscr.ffcs[i].data += 1;
5310
5311 if(prvscr.ffcs[j].flags&ffc_changeprev)
5312 prvscr.ffcs[i].data -= 1;
5313
5314 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5315 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5316 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5317
5318 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5319 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5320 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5321 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5322
5323 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5324 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5325 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5326 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5327 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5328
5329 if(prvscr.ffcs[i].flags&ffc_carryover)
5330 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5331 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5332
5333 prvscr.ffcs[i].flags&=~ffc_changer;
5334 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5335 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5336
5337 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5338 {
5339 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5340 }
5341
5342 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5343 {
5344 int32_t k=0;
5345
5346 if(prvscr.ffcs[j].flags&ffc_swapnext)
5347 k=j<(MAXFFCS-1)?j+1:0;
5348
5349 if(prvscr.ffcs[j].flags&ffc_swapprev)
5350 k=j>0?j-1:(MAXFFCS-1);
5351
5352 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5353 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5354 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5355 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5356 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5357 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5358 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5359 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5360 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5361 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5362 }
5363 }
5364 }
5365 }
5366 }
5367 }
5368
5369 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5370 {
5371 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5372 {
5373 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5374 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5375 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5376 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5377 }
5378 else
5379 {
5380 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5381 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5382 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5383 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5384 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5385 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5386
5387 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5388 {
5389 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5390
5391 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5392
5393 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5394
5395 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5396 }
5397 }
5398 }
5399 else
5400 {
5401 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5402 prvscr.ffcs[i].delay--;
5403 }
5404
5405 if(prvscr.ffcs[i].x<-32)
5406 {
5407 if(prvscr.flags6&fWRAPAROUNDFF)
5408 {
5409 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5410 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5411 }
5412 else
5413 {
5414 prvscr.ffcs[i].data = 0;
5415 prvscr.ffcs[i].flags&=~ffc_carryover;
5416 }
5417 }
5418
5419 if(prvscr.ffcs[i].y<-32)
5420 {
5421 if(prvscr.flags6&fWRAPAROUNDFF)
5422 {
5423 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5424 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5425 }
5426 else
5427 {
5428 prvscr.ffcs[i].data = 0;
5429 prvscr.ffcs[i].flags&=~ffc_carryover;
5430 }
5431 }
5432
5433 if(prvscr.ffcs[i].x>=288)
5434 {
5435 if(prvscr.flags6&fWRAPAROUNDFF)
5436 {
5437 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5438 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5439 }
5440 else
5441 {
5442 prvscr.ffcs[i].data = 0;
5443 prvscr.ffcs[i].flags&=~ffc_carryover;
5444 }
5445 }
5446
5447 if(prvscr.ffcs[i].y>=208)
5448 {
5449 if(prvscr.flags6&fWRAPAROUNDFF)
5450 {
5451 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5452 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5453 }
5454 else
5455 {
5456 prvscr.ffcs[i].data = 0;
5457 prvscr.ffcs[i].flags&=~ffc_carryover;
5458 }
5459 }
5460
5461 }
5462 }
5463 }
5464
5465 void zmap::goto_dmapscr(int dmap, int scr)
5466 {
5467 setCurrMap(DMaps[dmap].map);
5468 setCurrScr(scr+DMaps[dmap].xoff);
5469 }
5470 void zmap::goto_mapscr(int map, int scr)
5471 {
5472 setCurrMap(map);
5473 setCurrScr(scr);
5474 }
5475
5476 void zmap::dowarp(int32_t type, int32_t index)
5477 {
5478 set_warpback();
5479 if(type==0)
5480 {
5481
5482 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5483 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5484
5485 switch(screens[cursor.screen].tilewarptype[index])
5486 {
5487 case wtCAVE:
5488 case wtNOWARP:
5489 break;
5490
5491 default:
5492 goto_dmapscr(dmap, scr);
5493 break;
5494 }
5495 }
5496 else if(type==1)
5497 {
5498 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5499 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5500
5501 switch(screens[cursor.screen].sidewarptype[index])
5502 {
5503 case wtCAVE:
5504 case wtNOWARP:
5505 break;
5506
5507 default:
5508 goto_dmapscr(dmap, scr);
5509 break;
5510 }
5511 }
5512 }
5513
5514 extern int32_t prv_twon;
5515
5516 void zmap::prv_dowarp(int32_t type, int32_t index)
5517 {
5518 if(type==0)
5519 {
5520
5521 int32_t dmap=prvscr.tilewarpdmap[index];
5522 int32_t scr=prvscr.tilewarpscr[index];
5523
5524 switch(prvscr.tilewarptype[index])
5525 {
5526 case wtCAVE:
5527 case wtNOWARP:
5528 break;
5529
5530 default:
5531 //setCurrMap(DMaps[dmap].map);
5532 //setCurrScr(scr+DMaps[dmap].xoff);
5533 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5534 loadlvlpal(getcolor());
5535 rebuild_trans_table();
5536 //prv_cmbcycle=0;
5537 break;
5538 }
5539 }
5540 else if(type==1)
5541 {
5542 int32_t dmap=prvscr.sidewarpdmap[index];
5543 int32_t scr=prvscr.sidewarpscr[index];
5544
5545 switch(prvscr.sidewarptype[index])
5546 {
5547 case wtCAVE:
5548 case wtNOWARP:
5549 break;
5550
5551 default:
5552 //setCurrMap(DMaps[dmap].map);
5553 //setCurrScr(scr+DMaps[dmap].xoff);
5554 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5555 loadlvlpal(getcolor());
5556 rebuild_trans_table();
5557 //prv_cmbcycle=0;
5558 break;
5559 }
5560 }
5561
5562 if(prv_twon)
5563 {
5564 prv_time=get_prvscr()->timedwarptics;
5565 }
5566 }
5567
5568 void zmap::dowarp2(int32_t ring,int32_t index)
5569 {
5570 set_warpback();
5571 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5572 }
5573
5574 void zmap::set_warpback()
5575 {
5576 warpbackmap = cursor.map;
5577 warpbackscreen = cursor.screen;
5578 }
5579 bool zmap::has_warpback()
5580 {
5581 return warpbackmap && warpbackscreen
5582 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5583 }
5584 void zmap::warpback()
5585 {
5586 if(!has_warpback())
5587 return;
5588
5589 int m = cursor.map, s = cursor.screen;
5590 goto_mapscr(*warpbackmap, *warpbackscreen);
5591 warpbackmap = m;
5592 warpbackscreen = s;
5593 }
5594
5595 bool save_msgstrs(const char *path)
5596 {
5597 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5598
5599 if(!f)
5600 {
5601 return false;
5602 }
5603
5604 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5605 {
5606 pack_fclose(f);
5607 return true;
5608 }
5609
5610 pack_fclose(f);
5611 return false;
5612 }
5613
5614 1 bool save_strings_tsv(const char *path)
5615 {
5616 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5617
5618
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5619 {
5620 return false;
5621 }
5622
5623
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5624 {
5625 1 pack_fclose(f);
5626 1 return true;
5627 }
5628
5629 pack_fclose(f);
5630 return false;
5631 1 }
5632
5633 bool save_msgstrs_text(const char *path)
5634 {
5635 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5636
5637 if(!f)
5638 {
5639 return false;
5640 }
5641
5642 if(writestrings_text(f)==0)
5643 {
5644 pack_fclose(f);
5645 return true;
5646 }
5647
5648 pack_fclose(f);
5649 return false;
5650 }
5651
5652 bool load_msgstrs(const char *path, int32_t startstring)
5653 {
5654 //these are here to bypass compiler warnings about unused arguments
5655 startstring=startstring;
5656
5657 dword section_id;
5658 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5659
5660 if(!f)
5661 {
5662 return false;
5663 }
5664
5665 if(!p_mgetl(&section_id,f))
5666 {
5667 return false;
5668 }
5669
5670 if(section_id==ID_STRINGS)
5671 {
5672 if(readstrings(f, &header)==0)
5673 {
5674 pack_fclose(f);
5675 return true;
5676 }
5677 else
5678 {
5679 pack_fclose(f);
5680 return false;
5681 }
5682 }
5683
5684 pack_fclose(f);
5685 return false;
5686 }
5687
5688 bool load_strings_tsv(const char *path)
5689 {
5690 try
5691 {
5692 parse_strings_tsv(util::read_text_file(path));
5693 }
5694 catch (std::exception& ex)
5695 {
5696 InfoDialog("Import .tsv Error", ex.what()).show();
5697 return false;
5698 }
5699 return true;
5700 }
5701
5702 bool save_pals(const char *path)
5703 {
5704 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5705
5706 if(!f)
5707 {
5708 return false;
5709 }
5710
5711 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5712 {
5713 pack_fclose(f);
5714 return true;
5715 }
5716
5717 pack_fclose(f);
5718 return false;
5719 }
5720
5721 bool load_pals(const char *path, int32_t startcset)
5722 {
5723 dword section_id;
5724 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5725
5726 if(!f)
5727 {
5728 return false;
5729 }
5730
5731 if(!p_mgetl(&section_id,f))
5732 {
5733 return false;
5734 }
5735
5736 if(section_id==ID_CSETS)
5737 {
5738 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5739 {
5740 pack_fclose(f);
5741 loadlvlpal(Color);
5742 return true;
5743 }
5744 else
5745 {
5746 pack_fclose(f);
5747 return false;
5748 }
5749 }
5750
5751 return false;
5752 }
5753
5754 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5755 bool save_guys(const char *path)
5756 {
5757 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5758
5759 if(!f)
5760 {
5761 return false;
5762 }
5763
5764 /*
5765 int32_t id = ID_GUYS;
5766 if(!p_mputl(id,f))
5767 {
5768 return false;
5769 }
5770 */
5771
5772 zquestheader h;
5773 h.zelda_version = 0x250;
5774 h.build = 21;
5775
5776 if(writeguys(f, &h)==0)
5777 {
5778 pack_fclose(f);
5779 return true;
5780 }
5781
5782 pack_fclose(f);
5783 return false;
5784 }
5785
5786 bool load_guys(const char *path)
5787 {
5788 dword section_id;
5789 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5790
5791 if(!f)
5792 {
5793 return false;
5794 }
5795
5796 if(!p_mgetl(&section_id,f))
5797 {
5798 pack_fclose(f);
5799 return false;
5800 }
5801
5802 zquestheader h;
5803 h.zelda_version = 0x250;
5804 h.build = 21;
5805
5806 if(section_id==ID_GUYS)
5807 {
5808 if(readguys(f, &h)==0)
5809 {
5810 pack_fclose(f);
5811 return true;
5812 }
5813 }
5814
5815 pack_fclose(f);
5816 return false;
5817 }
5818
5819
5820 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5821 bool save_combo_alias(const char *path)
5822 {
5823 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5824
5825 if(!f)
5826 {
5827 return false;
5828 }
5829
5830 zquestheader h;
5831 h.zelda_version = 0x250;
5832 h.build = 21;
5833
5834 if(writecomboaliases(f, 0, 0)==0)
5835 {
5836 pack_fclose(f);
5837 return true;
5838 }
5839
5840 pack_fclose(f);
5841 return false;
5842 }
5843
5844 bool load_combo_alias(const char *path)
5845 {
5846 dword section_id;
5847 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5848
5849 if(!f)
5850 {
5851 return false;
5852 }
5853
5854 if(!p_mgetl(&section_id,f))
5855 {
5856 pack_fclose(f);
5857 return false;
5858 }
5859
5860 zquestheader h;
5861 h.zelda_version = 0x250;
5862 h.build = 21;
5863
5864 if(section_id==ID_COMBOALIASES)
5865 {
5866 if(readcomboaliases(f, &h, 0, 0)==0)
5867 {
5868 pack_fclose(f);
5869 return true;
5870 }
5871 }
5872
5873 pack_fclose(f);
5874 return false;
5875 }
5876
5877 bool load_zgp(const char *path)
5878 {
5879 dword section_id;
5880 word section_version;
5881 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5882
5883 if(!f)
5884 return false;
5885
5886 if(!p_mgetl(&section_id,f))
5887 {
5888 pack_fclose(f);
5889 return false;
5890 }
5891
5892 if(section_id!=ID_GRAPHICSPACK)
5893 {
5894 pack_fclose(f);
5895 return false;
5896 }
5897
5898 //section version info
5899 if(!p_igetw(&section_version,f))
5900 {
5901 return 2;
5902 }
5903
5904 if(!read_deprecated_section_cversion(f))
5905 {
5906 return 3;
5907 }
5908
5909 //tiles
5910 if(!p_mgetl(&section_id,f))
5911 {
5912 pack_fclose(f);
5913 return false;
5914 }
5915
5916 if(section_id==ID_TILES)
5917 {
5918 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5919 {
5920 pack_fclose(f);
5921 init_tiles(true, &header);
5922 return false;
5923 }
5924 }
5925 else
5926 {
5927 pack_fclose(f);
5928 return false;
5929 }
5930
5931 //combos
5932 if(!p_mgetl(&section_id,f))
5933 {
5934 pack_fclose(f);
5935 return false;
5936 }
5937
5938 if(section_id==ID_COMBOS)
5939 {
5940 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5941 {
5942 pack_fclose(f);
5943 return false;
5944 }
5945 }
5946 else
5947 {
5948 pack_fclose(f);
5949 return false;
5950 }
5951
5952 //palettes
5953 if(!p_mgetl(&section_id,f))
5954 {
5955 pack_fclose(f);
5956 return false;
5957 }
5958
5959 if(section_id==ID_CSETS)
5960 {
5961 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5962 {
5963 pack_fclose(f);
5964 return false;
5965 }
5966 }
5967 else
5968 {
5969 pack_fclose(f);
5970 return false;
5971 }
5972
5973 //items
5974 if(!p_mgetl(&section_id,f))
5975 {
5976 pack_fclose(f);
5977 return false;
5978 }
5979
5980 if(section_id==ID_ITEMS)
5981 {
5982 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5983 {
5984 pack_fclose(f);
5985 return false;
5986 }
5987 }
5988 else
5989 {
5990 pack_fclose(f);
5991 return false;
5992 }
5993
5994 //weapons
5995 if(!p_mgetl(&section_id,f))
5996 {
5997 pack_fclose(f);
5998 return false;
5999 }
6000
6001 if(section_id==ID_WEAPONS)
6002 {
6003 if(readweapons(f, &header)!=0)
6004 {
6005 pack_fclose(f);
6006 return false;
6007 }
6008 }
6009 else
6010 {
6011 pack_fclose(f);
6012 return false;
6013 }
6014
6015 //read the triforce pieces info and make sure it worked
6016 //really do this?
6017
6018 //read the game icons info and make sure it worked
6019 if(!p_mgetl(&section_id,f))
6020 {
6021 pack_fclose(f);
6022 return false;
6023 }
6024
6025 if(section_id==ID_ICONS)
6026 {
6027 if(readgameicons(f, &header, &QMisc)!=0)
6028 {
6029 pack_fclose(f);
6030 return false;
6031 }
6032 }
6033 else
6034 {
6035 pack_fclose(f);
6036 return false;
6037 }
6038
6039 //read the misc colors info and map styles info and make sure it worked
6040 if(!p_mgetl(&section_id,f))
6041 {
6042 pack_fclose(f);
6043 return false;
6044 }
6045
6046 if(section_id==ID_COLORS)
6047 {
6048 if(readmisccolors(f, &header, &QMisc)!=0)
6049 {
6050 pack_fclose(f);
6051 return false;
6052 }
6053 }
6054 else
6055 {
6056 pack_fclose(f);
6057 return false;
6058 }
6059
6060 //read the door combo sets and make sure it worked
6061 if(!p_mgetl(&section_id,f))
6062 {
6063 pack_fclose(f);
6064 return false;
6065 }
6066
6067 if(section_id==ID_DOORS)
6068 {
6069 if(readdoorcombosets(f, &header)!=0)
6070 {
6071 pack_fclose(f);
6072 return false;
6073 }
6074 }
6075 else
6076 {
6077 pack_fclose(f);
6078 return false;
6079 }
6080
6081 //read the template screens and make sure it worked
6082 //really do this?
6083
6084 //yay! it worked! close the file and say everything was ok.
6085 loadlvlpal(Color);
6086 setup_combo_animations();
6087 setup_combo_animations2();
6088 pack_fclose(f);
6089 return true;
6090 }
6091
6092 bool save_zgp(const char *path)
6093 {
6094 reset_combo_animations();
6095 reset_combo_animations2();
6096
6097 //open the file
6098 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6099
6100 if(!f)
6101 return false;
6102
6103 dword section_id=ID_GRAPHICSPACK;
6104 dword section_version=V_GRAPHICSPACK;
6105
6106 //section id
6107 if(!p_mputl(section_id,f))
6108 {
6109 return 1;
6110 }
6111
6112 //section version info
6113 if(!p_iputw(section_version,f))
6114 {
6115 return 2;
6116 }
6117
6118 if(!write_deprecated_section_cversion(section_version,f))
6119 {
6120 return 3;
6121 }
6122
6123 //tiles
6124 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6125 {
6126 pack_fclose(f);
6127 return false;
6128 }
6129
6130 //combos
6131 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6132 {
6133 pack_fclose(f);
6134 return false;
6135 }
6136
6137 //palettes
6138 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6139 {
6140 pack_fclose(f);
6141 return false;
6142 }
6143
6144 //items
6145 if(writeitems(f, &header)!=0)
6146 {
6147 pack_fclose(f);
6148 return false;
6149 }
6150
6151 //weapons
6152 if(writeweapons(f, &header)!=0)
6153 {
6154 pack_fclose(f);
6155 return false;
6156 }
6157
6158 //write the triforce pieces info and make sure it worked
6159 //really do this?
6160
6161 //write the game icons info and make sure it worked
6162 if(writegameicons(f, &header)!=0)
6163 {
6164 pack_fclose(f);
6165 return false;
6166 }
6167
6168 //write the misc colors info and map styles info and make sure it worked
6169 if(writemisccolors(f, &header)!=0)
6170 {
6171 pack_fclose(f);
6172 return false;
6173 }
6174
6175 //write the door combo sets and make sure it worked
6176 if(writedoorcombosets(f, &header)!=0)
6177 {
6178 pack_fclose(f);
6179 return false;
6180 }
6181
6182 //write the template screens and make sure it worked
6183 //really do this?
6184
6185 pack_fclose(f);
6186 return true;
6187 }
6188
6189 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6190 {
6191 //open the file
6192 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6193
6194 if(!f)
6195 return false;
6196
6197 dword section_id=ID_SUBSCREEN;
6198 dword s_version=V_SUBSCREEN;
6199
6200 if(!p_mputl(section_id,f))
6201 {
6202 pack_fclose(f);
6203 return false;
6204 }
6205
6206 if(!p_iputw(s_version,f))
6207 {
6208 pack_fclose(f);
6209 return false;
6210 }
6211
6212 if(!write_deprecated_section_cversion(s_version,f))
6213 {
6214 pack_fclose(f);
6215 return false;
6216 }
6217
6218 if(savefrom.write(f))
6219 {
6220 pack_fclose(f);
6221 return false;
6222 }
6223
6224 pack_fclose(f);
6225 return true;
6226 }
6227
6228 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6229 {
6230 //open the file
6231 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6232
6233 if(!f)
6234 return false;
6235
6236 dword section_id;
6237 dword s_version;
6238
6239 if(!p_mgetl(&section_id,f))
6240 {
6241 pack_fclose(f);
6242 return false;
6243 }
6244
6245 if(section_id!=ID_SUBSCREEN)
6246 {
6247 pack_fclose(f);
6248 return false;
6249 }
6250
6251 if(!p_igetw(&s_version,f))
6252 {
6253 pack_fclose(f);
6254 return false;
6255 }
6256
6257 if(!read_deprecated_section_cversion(f))
6258 {
6259 pack_fclose(f);
6260 return false;
6261 }
6262
6263 if(s_version < 8)
6264 {
6265 subscreen_group g;
6266 memset(&g,0,sizeof(subscreen_group));
6267 if(read_one_old_subscreen(f,&g,s_version)!=0)
6268 {
6269 pack_fclose(f);
6270 return false;
6271 }
6272 if(g.ss_type != loadto.sub_type)
6273 {
6274 pack_fclose(f);
6275 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6276 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6277 return false;
6278 }
6279 loadto.clear();
6280 if(g.objects[0].type != ssoNULL)
6281 loadto.load_old(g);
6282 }
6283 else
6284 {
6285 ZCSubscreen tmp = ZCSubscreen();
6286 if (tmp.read(f, s_version))
6287 {
6288 pack_fclose(f);
6289 return false;
6290 }
6291 if(tmp.sub_type != loadto.sub_type)
6292 {
6293 pack_fclose(f);
6294 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6295 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6296 return false;
6297 }
6298 loadto.clear();
6299 loadto = tmp;
6300 }
6301
6302 pack_fclose(f);
6303 return true;
6304 }
6305
6306 bool setMapCount2(int32_t c)
6307 {
6308 int32_t oldmapcount=map_count;
6309 int32_t cur_map=Map.getCurrMap();
6310
6311 bound(c,1,MAXMAPS);
6312 map_count=c;
6313
6314 try
6315 {
6316 TheMaps.resize(c*MAPSCRS);
6317 Map.force_refr_pointer();
6318 map_autolayers.resize(c*6);
6319 }
6320 catch(...)
6321 {
6322 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6323 return false;
6324 }
6325
6326 bound(cur_map,0,c-1);
6327 if(map_count>oldmapcount)
6328 {
6329 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6330 {
6331 Map.setCurrMap(mc);
6332
6333 for(int32_t ms=0; ms<MAPSCRS; ms++)
6334 {
6335 Map.clearscr(ms);
6336 }
6337 }
6338 Map.setCurrMap(cur_map);
6339 }
6340 else
6341 {
6342 Map.setCurrMap(cur_map);
6343 if(!layers_valid(Map.CurrScr()))
6344 fix_layers(Map.CurrScr(), false);
6345
6346 for(int32_t i=0; i<MAXDMAPS; i++)
6347 {
6348 if(DMaps[i].map>=map_count)
6349 {
6350 DMaps[i].map=map_count-1;
6351 }
6352 }
6353 }
6354
6355 return true;
6356 }
6357
6358 extern BITMAP *bmap;
6359
6360 static bool loading_file_new = false;
6361 int32_t init_quest(std::string tileset_path)
6362 {
6363 if (tileset_path.empty())
6364 tileset_path = DEFAULT_TILESET;
6365
6366 loading_file_new = true;
6367 load_quest(tileset_path.c_str());
6368 loading_file_new = false;
6369
6370 set_window_title("ZC Editor - Untitled Quest");
6371 zinit.last_map = 0;
6372 zinit.last_screen = 0;
6373
6374 if(bmap != NULL)
6375 {
6376 destroy_bitmap(bmap);
6377 bmap=NULL;
6378 }
6379
6380 return 0;
6381 }
6382
6383 void set_questpwd(std::string_view pwd, bool use_keyfile)
6384 {
6385 header.use_keyfile=use_keyfile;
6386
6387 // string_view actually has some quirks that make it less than ideal here.
6388 // It'd probably be best to replace it, but this works for now.
6389 memset(header.password, 0, 256);
6390 strcpy(header.password, pwd.data());
6391 header.dirty_password=true;
6392
6393 cvs_MD5Context ctx;
6394 cvs_MD5Init(&ctx);
6395 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6396 cvs_MD5Final(header.pwd_hash, &ctx);
6397 }
6398
6399
6400 bool is_null_pwd_hash(uint8_t *pwd_hash)
6401 {
6402 cvs_MD5Context ctx;
6403 uint8_t md5sum[16];
6404 char pwd[2]="";
6405
6406 cvs_MD5Init(&ctx);
6407 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6408 cvs_MD5Final(md5sum, &ctx);
6409
6410 return (memcmp(md5sum,pwd_hash,16)==0);
6411 }
6412
6413 static DIALOG pwd_dlg[] =
6414 {
6415 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6416 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6417 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6418 // 2 (filename)
6419 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6420 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6421 // 4 (challenge hash)
6422 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6423 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6424 // 6 (password)
6425 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6426 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6427 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6428 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6429 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6430 };
6431
6432 int32_t reverse_string(char* str)
6433 {
6434
6435 if(NULL==str)
6436 {
6437 return -1; //no string
6438 }
6439
6440 int32_t l=(int32_t)strlen(str)-1; //get the string length
6441
6442 if(1==l)
6443 {
6444 return 1;
6445 }
6446
6447 char c;
6448
6449 for(int32_t x=0; x < l; x++,l--)
6450 {
6451 c = str[x];
6452 str[x] = str[l];
6453 str[l] = c;
6454 }
6455
6456 return 0;
6457 }
6458
6459 #ifdef __GNUC__
6460 #pragma GCC diagnostic push
6461 #pragma GCC diagnostic ignored "-Wunreachable-code"
6462 #endif
6463
6464 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6465 {
6466
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6467 11 return 1;
6468
6469 #ifdef __EMSCRIPTEN__
6470 return 1;
6471 #endif
6472
6473 //Protection against compiling a release version with password protection off.
6474 static bool passguard = false;
6475
6476 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6477 #define MUST_HAVE_PASSWORD
6478 passguard = true;
6479 #endif
6480
6481 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6482 #if (defined _MSC_VER || defined _NPASS)
6483 return 1;
6484 #endif
6485 #endif
6486 if(devpwd()) return 1;
6487
6488 char hash_string[33];
6489
6490 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6491 {
6492 return 1;
6493 }
6494
6495 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6496 return true;
6497
6498 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6499 pwd_dlg[2].dp=get_filename(filename);
6500 cvs_MD5Context ctx;
6501 uint8_t md5sum[16]={0};
6502 char response[33]="";
6503 char prompt[256]="";
6504
6505 memcpy(md5sum, hdr->pwd_hash, 16);
6506
6507 for(int32_t i=0; i<300; ++i)
6508 {
6509 for(int32_t j=0; j<16; ++j)
6510 {
6511 sprintf(response+j*2, "%02x", md5sum[j]);
6512 }
6513
6514 if(i&1)
6515 {
6516 reverse_string(response);
6517 }
6518
6519 if(i==149)
6520 {
6521 strcpy(hash_string, response);
6522 }
6523
6524 cvs_MD5Init(&ctx);
6525 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6526 cvs_MD5Final(md5sum, &ctx);
6527 }
6528
6529 pwd_dlg[4].dp=hash_string;
6530
6531 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6532 {
6533 sprintf(prompt,"%s",response);
6534 }
6535
6536 pwd_dlg[6].dp=prompt;
6537
6538 large_dialog(pwd_dlg);
6539
6540 int32_t cancel = do_zqdialog(pwd_dlg,6);
6541
6542 if(cancel == 8)
6543 return 2;
6544
6545 bool ret=check_questpwd(hdr, prompt);
6546
6547 if(!ret)
6548 {
6549 ret=(strcmp(response,prompt)==0);
6550 }
6551 return ret ? 1 : 0;
6552 11 }
6553
6554 void set_rules(byte* newrules);
6555 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6556 {
6557 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6558
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6559 {
6560
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6561
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6562 "\nWould you like to apply them?"
6563 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6564 11 [&](bool ret,bool dsa)
6565 {
6566 if(ret)
6567 {
6568 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6569 }
6570 if(dsa)
6571 {
6572 zc_set_config("zquest",cfg,1);
6573 }
6574 },
6575
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6576 0,false, //timeout - none
6577 true //"Don't show this again"
6578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6579 11 }
6580 11 }
6581
6582 #ifdef __GNUC__
6583 #pragma GCC diagnostic pop
6584 #endif
6585
6586 11 int32_t load_quest(const char *filename, bool show_progress)
6587 {
6588 char buf[2048];
6589 byte skip_flags[4];
6590
6591 11 dword tileset_flags = 0;
6592
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6593 {
6594 44 skip_flags[i]=0;
6595 44 }
6596
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6597 7634 set_qr(i,0);
6598 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6599
6600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6601 {
6602 init_quest(DEFAULT_TILESET);
6603 }
6604 else
6605 {
6606 11 int32_t accessret = quest_access(filename, &header);
6607
6608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6609 {
6610 init_quest(DEFAULT_TILESET);
6611
6612 if(accessret == 0)
6613 ret=qe_pwd;
6614 else
6615 ret=qe_cancel;
6616 }
6617 else
6618 {
6619 11 Map.clear();
6620 11 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6621 11 Map.setCurrScr(zinit.last_screen);
6622
6623
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6624
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6625
6626 extern int32_t current_mappage;
6627 11 current_mappage = 0;
6628 11 bool found_default = false;
6629
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6630 {
6631 83 auto &pg = map_page[q];
6632
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6633 {
6634 2 current_mappage = q;
6635 2 break;
6636 }
6637
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6638 72 continue;
6639 else
6640 {
6641 9 current_mappage = q;
6642 9 found_default = true;
6643 }
6644 9 }
6645
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6646
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6647
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6648 11 saved = true;
6649
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6650
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6651
6652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6653 {
6654 destroy_bitmap(bmap);
6655 bmap=NULL;
6656 }
6657
6658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6659 {
6660 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6661 set_window_title(buf);
6662 }
6663 11 }
6664 }
6665
6666 11 Map.ClearCommandHistory();
6667
6668
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6669 {
6670 void load_size_poses();
6671 load_size_poses();
6672 }
6673
6674 11 return ret;
6675 }
6676
6677 int32_t load_tileset(const char *filename, dword tsetflags)
6678 {
6679 byte skip_flags[4];
6680
6681 for(int32_t i=0; i<4; ++i)
6682 skip_flags[i]=0;
6683 for(int32_t i=0; i<qr_MAX; i++)
6684 set_qr(i,0);
6685 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6686
6687 if(ret!=qe_OK)
6688 init_quest(DEFAULT_TILESET);
6689 else
6690 {
6691 if(tsetflags & TILESET_BUGFIX)
6692 applyRuleTemplate(ruletemplateFixCompat);
6693
6694 int32_t accessret = quest_access(filename, &header);
6695
6696 if(accessret != 1)
6697 {
6698 init_quest(DEFAULT_TILESET);
6699
6700 if(accessret == 0)
6701 ret=qe_pwd;
6702 else
6703 ret=qe_cancel;
6704 }
6705 else
6706 {
6707 Map.clear();
6708 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6709 Map.setCurrScr(zinit.last_screen);
6710 extern int32_t current_mappage;
6711 current_mappage = 0;
6712 bool found_default = false;
6713 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6714 {
6715 auto &pg = map_page[q];
6716 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6717 {
6718 current_mappage = q;
6719 break;
6720 }
6721 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6722 continue;
6723 else
6724 {
6725 current_mappage = q;
6726 found_default = true;
6727 }
6728 }
6729 refresh(rALL);
6730 refresh_pal();
6731 set_rules(quest_rules);
6732
6733 if(bmap != NULL)
6734 {
6735 destroy_bitmap(bmap);
6736 bmap=NULL;
6737 }
6738
6739 set_window_title("ZC Editor - Untitled Quest");
6740 first_save = saved = false;
6741 memset(filepath,0,255);
6742 memset(temppath,0,255);
6743 }
6744 }
6745
6746 Map.ClearCommandHistory();
6747
6748 return ret;
6749 }
6750
6751 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6752 {
6753
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6754 new_return(1);
6755
6756
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6757 new_return(2);
6758
6759
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6760 new_return(3);
6761
6762
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6763 new_return(4);
6764
6765
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6766 {
6767
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6768 new_return(5);
6769
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6770 new_return(6);
6771 1363650 }
6772
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6773 new_return(7);
6774
6775
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6776 new_return(8);
6777
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6778 new_return(9);
6779
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6780 new_return(10);
6781
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6782 new_return(11);
6783
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6784 new_return(12);
6785
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6786 new_return(13);
6787
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6788 new_return(14);
6789
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6790 new_return(15);
6791
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6792 new_return(16);
6793
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6794 new_return(17);
6795
6796
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6797 new_return(18);
6798
6799
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6800 new_return(19);
6801
6802
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6803 new_return(20);
6804
6805
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6806 new_return(21);
6807
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6808 new_return(22);
6809
6810
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6811 new_return(23);
6812
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6813 new_return(24);
6814
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6815 new_return(25);
6816
6817
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6818 new_return(26);
6819
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6820
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6821 new_return(27);
6822
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6823 new_return(28);
6824 272730 return 0;
6825 }
6826
6827 130 bool write_midi(MIDI *m,PACKFILE *f)
6828 {
6829 int32_t c;
6830
6831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6832
6833
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6834 {
6835
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6836
6837
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6838 {
6839
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6840 return false;
6841 1264 }
6842 4160 }
6843
6844 130 return true;
6845 130 }
6846
6847 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6848 {
6849 9 dword section_id=ID_HEADER;
6850 9 dword section_version=V_HEADER;
6851 9 dword section_size=0;
6852
6853 //file header string
6854
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6855 {
6856 new_return(1);
6857 }
6858
6859 //section id
6860
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6861 {
6862 new_return(2);
6863 }
6864
6865 //section version info
6866
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6867 {
6868 new_return(3);
6869 }
6870
6871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6872 {
6873 new_return(4);
6874 }
6875
6876
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6877 {
6878 18 fake_pack_writing=(writecycle==0);
6879
6880 //section size
6881
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6882 {
6883 new_return(5);
6884 }
6885
6886 18 writesize=0;
6887
6888 //finally... section data
6889
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6890 {
6891 new_return(6);
6892 }
6893
6894
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6895 {
6896 new_return(7);
6897 }
6898
6899
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6900 {
6901 new_return(8);
6902 }
6903
6904
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6905 {
6906 new_return(10);
6907 }
6908
6909
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6910 {
6911 new_return(11);
6912 }
6913
6914
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6915 {
6916 new_return(12);
6917 }
6918
6919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6920 {
6921 new_return(13);
6922 }
6923
6924
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6925 {
6926 new_return(14);
6927 }
6928
6929
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6930 {
6931 new_return(15);
6932 }
6933
6934
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6935 {
6936 new_return(16);
6937 }
6938
6939
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6940 {
6941 new_return(17);
6942 }
6943
6944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6945 {
6946 new_return(19);
6947 }
6948
6949
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6950 //this is for map count, it seems. -Z
6951 {
6952 new_return(20);
6953 }
6954
6955 18 auto version = getVersion();
6956
6957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6958 {
6959 new_return(21);
6960 }
6961
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6962 {
6963 new_return(22);
6964 }
6965
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6966 {
6967 new_return(23);
6968 }
6969 // Fourth component is deprecated.
6970
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6971 {
6972 new_return(24);
6973 }
6974
6975 // Numerous prerelease stages is deprecated.
6976
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6977 {
6978 new_return(25);
6979 }
6980
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6981 {
6982 new_return(26);
6983 }
6984
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6985 {
6986 new_return(27);
6987 }
6988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6989 {
6990 new_return(28);
6991 }
6992
6993
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6994 {
6995 new_return(29);
6996 }
6997
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6998 {
6999 new_return(30);
7000 }
7001
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
7002 {
7003 new_return(31);
7004 }
7005
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
7006 {
7007 new_return(32);
7008 }
7009
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
7010 {
7011 new_return(33);
7012 }
7013
7014 // This is no longer set to anything.
7015 const char* tempsig[256];
7016 18 memset(tempsig, 0, 256);
7017
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
7018 {
7019 new_return(34);
7020 }
7021
7022 char tempcompilersig[256];
7023 18 memset(tempcompilersig, 0, 256);
7024 18 strcpy(tempcompilersig, COMPILER_NAME);
7025
7026
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
7027 {
7028 new_return(35);
7029 }
7030
7031 char tempcompilerversion[256];
7032 18 memset(tempcompilerversion, 0, 256);
7033 #ifdef _MSC_VER
7034 zc_itoa(_MSC_VER,tempcompilerversion,10);
7035 #else
7036 18 strcpy(tempcompilerversion, COMPILER_VERSION);
7037 #endif
7038
7039
7040
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
7041 {
7042 new_return(36);
7043 }
7044
7045
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
7046 {
7047 new_return(37);
7048 }
7049
7050 // V_ZC_COMPILERSIG - a deprecated version field.
7051
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
7052 {
7053 new_return(38);
7054 }
7055 #ifdef _MSC_VER
7056 if(!p_iputl((_MSC_VER / 100),f))
7057 {
7058 new_return(39);
7059 }
7060 #else
7061
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7062 {
7063 new_return(39);
7064 }
7065 #endif
7066
7067
7068
7069 #ifdef _MSC_VER
7070 if(!p_iputl((_MSC_VER % 100),f))
7071 {
7072 new_return(41);
7073 }
7074 #else
7075
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7076 {
7077 new_return(41);
7078 }
7079 #endif
7080
7081 #ifdef _MSC_VER
7082 # if _MSC_VER >= 1400
7083 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7084 {
7085 new_return(40);
7086 }
7087 # else
7088 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7089 {
7090 new_return(40);
7091 }
7092 #endif
7093 #else
7094
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7095 {
7096 new_return(40);
7097 }
7098 #endif
7099
7100 #ifdef _MSC_VER
7101 if(!p_iputl((_MSC_BUILD),f))
7102 {
7103 new_return(42);
7104 }
7105 #else
7106
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7107 {
7108 new_return(42);
7109 }
7110 #endif
7111
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7112 {
7113 new_return(43);
7114 }
7115
7116 // Modules were removed (replaced by zinfo).
7117 char tempmodulename[1024];
7118 18 memset(tempmodulename, 0, 1024);
7119
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7120 {
7121 new_return(44);
7122 }
7123
7124 char tempdate[256];
7125 18 memset(tempdate, 0, 256);
7126 18 strcpy(tempdate, __DATE__);
7127
7128
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7129 {
7130 new_return(45);
7131 }
7132 char temptime[256];
7133 18 memset(temptime, 0, 256);
7134 18 strcpy(temptime, __TIME__);
7135
7136
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7137 {
7138 new_return(46);
7139 }
7140
7141
7142 char temptimezone[6];
7143 18 memset(temptimezone, 0, 6);
7144 18 strcpy(temptimezone, __TIMEZONE__);
7145
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7146 {
7147 new_return(47);
7148 }
7149
7150
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7151 {
7152 new_return(48);
7153 }
7154
7155
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7156 {
7157 new_return(49);
7158 }
7159
7160
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7161 {
7162 new_return(50);
7163 }
7164
7165
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7166 {
7167 9 section_size=writesize;
7168 9 }
7169 18 }
7170
7171
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7172 {
7173 char ebuf[80];
7174 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7175 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7176 }
7177
7178 9 new_return(0);
7179 }
7180
7181 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7182 {
7183 //these are here to bypass compiler warnings about unused arguments
7184 9 Header=Header;
7185
7186 9 dword section_id=ID_RULES;
7187 9 dword section_version=V_RULES;
7188 9 dword section_size=0;
7189
7190 //section id
7191
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7192 {
7193 new_return(1);
7194 }
7195
7196 //section version info
7197
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7198 {
7199 new_return(2);
7200 }
7201
7202
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7203 {
7204 new_return(3);
7205 }
7206
7207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7208 {
7209 new_return(6);
7210 }
7211
7212
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7213 {
7214 18 fake_pack_writing=(writecycle==0);
7215
7216 //section size
7217
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7218 {
7219 new_return(4);
7220 }
7221
7222 18 writesize=0;
7223
7224 //finally... section data
7225
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7226 {
7227 new_return(5);
7228 }
7229
7230
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7231 {
7232 9 section_size=writesize;
7233 9 }
7234 18 }
7235
7236
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7237 {
7238 char ebuf[80];
7239 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7240 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7241 }
7242
7243 9 new_return(0);
7244 }
7245
7246
7247 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7248 {
7249 //these are here to bypass compiler warnings about unused arguments
7250 9 Header=Header;
7251
7252 9 dword section_id=ID_DOORS;
7253 9 dword section_version=V_DOORS;
7254 9 dword section_size=0;
7255
7256 //section id
7257
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7258 {
7259 new_return(1);
7260 }
7261
7262 //section version info
7263
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7264 {
7265 new_return(2);
7266 }
7267
7268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7269 {
7270 new_return(3);
7271 }
7272
7273
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7274 {
7275 18 fake_pack_writing=(writecycle==0);
7276
7277 //section size
7278
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7279 {
7280 new_return(4);
7281 }
7282
7283 18 writesize=0;
7284
7285 //finally... section data
7286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7287 {
7288 new_return(5);
7289 }
7290
7291
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7292 {
7293 //name
7294 char name[21];
7295 320 memset(name, 21, (char)0);
7296 320 strcpy(name, DoorComboSetNames[i].c_str());
7297
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7298 {
7299 new_return(6);
7300 }
7301
7302 //up door
7303
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7304 {
7305
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7306 {
7307
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7308 {
7309 new_return(7);
7310 }
7311 11520 }
7312 2880 }
7313
7314
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7315 {
7316
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7317 {
7318
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7319 {
7320 new_return(8);
7321 }
7322 11520 }
7323 2880 }
7324
7325 //down door
7326
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7327 {
7328
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7329 {
7330
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7331 {
7332 new_return(9);
7333 }
7334 11520 }
7335 2880 }
7336
7337
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7338 {
7339
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7340 {
7341
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7342 {
7343 new_return(10);
7344 }
7345 11520 }
7346 2880 }
7347
7348
7349 //left door
7350
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7351 {
7352
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7353 {
7354
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7355
7356 {
7357 new_return(11);
7358 }
7359 17280 }
7360 2880 }
7361
7362
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7363 {
7364
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7365 {
7366
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7367 {
7368 new_return(12);
7369 }
7370 17280 }
7371 2880 }
7372
7373 //right door
7374
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7375 {
7376
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7377 {
7378
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7379 {
7380 new_return(13);
7381 }
7382 17280 }
7383 2880 }
7384
7385
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7386 {
7387
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7388 {
7389
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7390 {
7391 new_return(14);
7392 }
7393 17280 }
7394 2880 }
7395
7396
7397 //up bomb rubble
7398
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7399 {
7400
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7401 {
7402 new_return(15);
7403 }
7404 640 }
7405
7406
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7407 {
7408
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7409 {
7410 new_return(16);
7411 }
7412 640 }
7413
7414 //down bomb rubble
7415
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7416 {
7417
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7418 {
7419 new_return(17);
7420 }
7421 640 }
7422
7423
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7424 {
7425
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7426 {
7427 new_return(18);
7428 }
7429 640 }
7430
7431 //left bomb rubble
7432
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7433 {
7434
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7435 {
7436 new_return(19);
7437 }
7438 960 }
7439
7440
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7441 {
7442
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7443 {
7444 new_return(20);
7445 }
7446 960 }
7447
7448 //right bomb rubble
7449
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7450 {
7451
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7452 {
7453 new_return(21);
7454 }
7455 960 }
7456
7457
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7458 {
7459
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7460 {
7461 new_return(22);
7462 }
7463 960 }
7464
7465 //walkthrough stuff
7466
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7467 {
7468
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7469 {
7470 new_return(23);
7471 }
7472 1280 }
7473
7474
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7475 {
7476
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7477 {
7478 new_return(24);
7479 }
7480 1280 }
7481
7482 //flags
7483
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7484 {
7485
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7486 {
7487 new_return(25);
7488 }
7489 640 }
7490 320 }
7491
7492
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7493 {
7494 9 section_size=writesize;
7495 9 }
7496 18 }
7497
7498
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7499 {
7500 char ebuf[80];
7501 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7502 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7503 }
7504
7505 9 new_return(0);
7506 }
7507
7508 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7509 {
7510 //these are here to bypass compiler warnings about unused arguments
7511 9 version=version;
7512 9 build=build;
7513
7514 9 word dmap_count=count_dmaps();
7515 9 dword section_id=ID_DMAPS;
7516 9 dword section_version=V_DMAPS;
7517 9 dword section_size=0;
7518
7519 //section id
7520
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7521 {
7522 new_return(1);
7523 }
7524
7525 //section version info
7526
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7527 {
7528 new_return(2);
7529 }
7530
7531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7532 {
7533 new_return(3);
7534 }
7535
7536
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7537 {
7538 18 fake_pack_writing=(writecycle==0);
7539
7540 //section size
7541
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7542 {
7543 new_return(4);
7544 }
7545
7546 18 writesize=0;
7547
7548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7550
7551 //finally... section data
7552
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7553 {
7554 new_return(5);
7555 }
7556
7557
7558
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7559 {
7560 9216 DMaps[i].validate_subscreens();
7561
7562
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7563 {
7564 new_return(6);
7565 }
7566
7567
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7568 {
7569 new_return(7);
7570 }
7571
7572
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7573 {
7574 new_return(8);
7575 }
7576
7577
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7578 {
7579 new_return(9);
7580 }
7581
7582
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7583 {
7584 new_return(10);
7585 }
7586
7587
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7588 {
7589 new_return(11);
7590 }
7591
7592
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7593 {
7594 new_return(12);
7595 }
7596
7597
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7598 {
7599 new_return(13);
7600 }
7601
7602
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7603 {
7604
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7605 {
7606 new_return(14);
7607 }
7608 73728 }
7609
7610
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7611 {
7612 new_return(15);
7613 }
7614
7615
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7616 {
7617 new_return(16);
7618 }
7619
7620
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7621 {
7622 new_return(17);
7623 }
7624
7625
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[0],f))
7626 {
7627 new_return(18);
7628 }
7629
7630
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[0],f))
7631 {
7632 new_return(19);
7633 }
7634
7635
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[1],f))
7636 {
7637 new_return(20);
7638 }
7639
7640
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[1],f))
7641 {
7642 new_return(21);
7643 }
7644
7645
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[0],f))
7646 {
7647 new_return(22);
7648 }
7649
7650
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[0],f))
7651 {
7652 new_return(23);
7653 }
7654
7655
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[1],f))
7656 {
7657 new_return(24);
7658 }
7659
7660
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[1],f))
7661 {
7662 new_return(25);
7663 }
7664
7665
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7666 {
7667 new_return(26);
7668 }
7669
7670
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7671 {
7672 new_return(25);
7673 }
7674
7675
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7676 {
7677 new_return(26);
7678 }
7679
7680
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7681 {
7682 new_return(27);
7683 }
7684
7685 byte disabled[32];
7686 9216 memset(disabled,0,32);
7687
7688
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7689 {
7690
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359296 times.
2359296 if(DMaps[i].disableditems[j])
7691 {
7692 disabled[j/8] |= (1 << (j%8));
7693 }
7694 2359296 }
7695
7696
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7697 {
7698 new_return(28);
7699 }
7700
7701
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7702 {
7703 new_return(29);
7704 }
7705
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7706 {
7707 new_return(30);
7708 }
7709
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7710 {
7711 new_return(31);
7712 }
7713
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7714 {
7715
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7716 {
7717 new_return(32);
7718 }
7719
7720 73728 }
7721
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7722 {
7723
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7724 {
7725
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7726 {
7727 new_return(33);
7728 }
7729 4792320 }
7730 73728 }
7731
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7732 {
7733 new_return(34);
7734 }
7735
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7736 {
7737 new_return(35);
7738 }
7739
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7740 {
7741
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7742 {
7743 new_return(36);
7744 }
7745 73728 }
7746
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7747 {
7748
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7749 {
7750
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7751 {
7752 new_return(37);
7753 }
7754 4792320 }
7755 73728 }
7756
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7757 {
7758 new_return(38);
7759 }
7760
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7761 {
7762
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7763 {
7764 new_return(39);
7765 }
7766 73728 }
7767
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7768 {
7769
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7770 {
7771
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7772 {
7773 new_return(40);
7774 }
7775 4792320 }
7776 73728 }
7777
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7778 {
7779 new_return(41);
7780 }
7781
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7782 {
7783 new_return(42);
7784 }
7785
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7786 {
7787 new_return(43);
7788 }
7789
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7790 {
7791 new_return(44);
7792 }
7793
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7794 {
7795 new_return(45);
7796 }
7797
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7798 new_return(46);
7799
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7800 new_return(47);
7801
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[i].flags & dmfCUSTOM_GRAVITY)
7802 {
7803 if (!p_iputzf(DMaps[i].dmap_gravity, f))
7804 new_return(48);
7805 if (!p_iputzf(DMaps[i].dmap_terminal_v, f))
7806 new_return(49);
7807 }
7808 9216 }
7809
7810
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7811 {
7812 9 section_size=writesize;
7813 9 }
7814 18 }
7815
7816
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7817 {
7818 char ebuf[80];
7819 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7820 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7821 }
7822
7823 9 new_return(0);
7824 }
7825
7826 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7827 {
7828 //these are here to bypass compiler warnings about unused arguments
7829 9 Header=Header;
7830
7831 9 dword section_id=ID_COLORS;
7832 9 dword section_version=V_COLORS;
7833 9 dword section_size = 0;
7834
7835 //section id
7836
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7837 {
7838 new_return(1);
7839 }
7840
7841
7842 //section version info
7843
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7844 {
7845 new_return(2);
7846 }
7847
7848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7849 {
7850 new_return(3);
7851 }
7852
7853
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7854 {
7855 18 fake_pack_writing=(writecycle==0);
7856
7857 //section size
7858
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7859 {
7860 new_return(4);
7861 }
7862
7863 18 writesize=0;
7864
7865
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7866 {
7867 new_return(5);
7868 }
7869
7870
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7871 {
7872 new_return(6);
7873 }
7874
7875
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7876 {
7877 new_return(7);
7878 }
7879
7880
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7881 {
7882 new_return(8);
7883 }
7884
7885
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7886 {
7887 new_return(9);
7888 }
7889
7890
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7891 {
7892 new_return(10);
7893 }
7894
7895
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7896 {
7897 new_return(11);
7898 }
7899
7900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7901 {
7902 new_return(12);
7903 }
7904
7905
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7906 {
7907 new_return(13);
7908 }
7909
7910
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7911 {
7912 new_return(14);
7913 }
7914
7915
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7916 {
7917 new_return(15);
7918 }
7919
7920
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7921 {
7922 new_return(16);
7923 }
7924
7925
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7926 {
7927 new_return(17);
7928 }
7929
7930
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7931 {
7932 new_return(18);
7933 }
7934
7935
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7936 {
7937 new_return(19);
7938 }
7939
7940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7941 {
7942 new_return(20);
7943 }
7944
7945
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7946 {
7947 new_return(21);
7948 }
7949
7950
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7951 {
7952 new_return(22);
7953 }
7954
7955
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7956 {
7957 new_return(23);
7958 }
7959
7960
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7961 {
7962 new_return(24);
7963 }
7964
7965
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7966 {
7967 new_return(31);
7968 }
7969
7970
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7971 {
7972 new_return(32);
7973 }
7974
7975
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7976 {
7977 new_return(33);
7978 }
7979
7980
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7981 {
7982 new_return(34);
7983 }
7984
7985
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7986 {
7987 new_return(35);
7988 }
7989
7990
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7991 {
7992 new_return(36);
7993 }
7994
7995
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7996 {
7997 new_return(37);
7998 }
7999
8000
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
8001 {
8002 new_return(38);
8003 }
8004
8005
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
8006 {
8007 new_return(39);
8008 }
8009
8010
8011
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8012 {
8013 9 section_size=writesize;
8014 9 }
8015 18 }
8016
8017
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8018 {
8019 char ebuf[80];
8020 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8021 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8022 }
8023
8024 9 new_return(0);
8025 }
8026
8027 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
8028 {
8029 //these are here to bypass compiler warnings about unused arguments
8030 9 Header=Header;
8031
8032 9 dword section_id=ID_ICONS;
8033 9 dword section_version=V_ICONS;
8034 9 dword section_size = 0;
8035
8036 //section id
8037
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8038 {
8039 new_return(1);
8040 }
8041
8042 //section version info
8043
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8044 {
8045 new_return(2);
8046 }
8047
8048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8049 {
8050 new_return(3);
8051 }
8052
8053
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8054 {
8055 18 fake_pack_writing=(writecycle==0);
8056
8057 //section size
8058
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8059 {
8060 new_return(4);
8061 }
8062
8063 18 writesize=0;
8064
8065
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
8066 {
8067
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
8068 {
8069 new_return(5);
8070 }
8071 72 }
8072
8073
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8074 {
8075 9 section_size=writesize;
8076 9 }
8077 18 }
8078
8079
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8080 {
8081 char ebuf[80];
8082 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8083 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8084 }
8085
8086 9 new_return(0);
8087 }
8088
8089 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8090 {
8091 //these are here to bypass compiler warnings about unused arguments
8092 9 Header=Header;
8093
8094 9 dword section_id=ID_MISC;
8095 9 dword section_version=V_MISC;
8096 9 word shops=count_shops(&QMisc);
8097 9 word infos=count_infos(&QMisc);
8098 9 word warprings=count_warprings(&QMisc);
8099 9 word triforces=8;
8100 9 dword section_size = 0;
8101
8102 //section id
8103
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8104 {
8105 new_return(1);
8106 }
8107
8108
8109 //section version info
8110
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8111 {
8112 new_return(2);
8113 }
8114
8115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8116 {
8117 new_return(3);
8118 }
8119
8120
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8121 {
8122 18 fake_pack_writing=(writecycle==0);
8123
8124 //section size
8125
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8126 {
8127 new_return(4);
8128 }
8129
8130 18 writesize=0;
8131
8132 //shops
8133
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8134 {
8135 new_return(5);
8136 }
8137
8138
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8139 {
8140
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8141 {
8142 new_return(6);
8143 }
8144
8145
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8146 {
8147
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8148 {
8149 new_return(7);
8150 }
8151 480 }
8152
8153
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8154 {
8155
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8156 {
8157 new_return(8);
8158 }
8159 480 }
8160
8161
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8162 {
8163
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8164 {
8165 new_return(9);
8166 }
8167 480 }
8168 160 }
8169
8170 //infos
8171
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8172 {
8173 new_return(10);
8174 }
8175
8176
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8177 {
8178
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8179 {
8180 new_return(11);
8181 }
8182
8183
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8184 {
8185
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8186 {
8187 new_return(12);
8188 }
8189 480 }
8190
8191
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8192 {
8193
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8194 {
8195 new_return(13);
8196 }
8197 480 }
8198 160 }
8199
8200 //warp rings
8201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8202 {
8203 new_return(14);
8204 }
8205
8206
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8207 {
8208
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8209 {
8210
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8211 {
8212 new_return(15);
8213 }
8214 1872 }
8215
8216
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8217 {
8218
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8219 {
8220 new_return(16);
8221 }
8222 1872 }
8223
8224
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8225 {
8226 new_return(17);
8227 }
8228 208 }
8229
8230 //triforce pieces
8231
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8232 {
8233
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8234 {
8235 new_return(18);
8236 }
8237 144 }
8238
8239 //end string
8240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8241 {
8242 new_return(19);
8243 }
8244
8245 //V_MISC >= 8
8246
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8247 {
8248
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8249 {
8250
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8251 {
8252 new_return(20);
8253 }
8254 480 }
8255 160 }
8256 //V_MISC >= 9
8257
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8258 {
8259
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8260 new_return(21);
8261 576 }
8262
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8263 {
8264
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8265
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8266 new_return(22);
8267 576 }
8268 //V_MISC >= 11
8269
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8270 new_return(23);
8271
8272 //V_MISC >= 12
8273
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8274 {
8275
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8276 new_return(24);
8277 4608 }
8278
8279 //V_MISC >= 13
8280
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8281 {
8282 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8283
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8284 new_return(25);
8285
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8286 {
8287
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8288 new_return(25);
8289
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8290 new_return(25);
8291 3456 }
8292
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8293 new_return(25);
8294
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8295 new_return(25);
8296 1152 }
8297
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8298 {
8299 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8300
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8301 new_return(26);
8302
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8303 {
8304
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8305 new_return(26);
8306
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8307 new_return(26);
8308
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8309 new_return(26);
8310
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8311 new_return(26);
8312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8313 new_return(26);
8314 13824 }
8315 4608 }
8316
8317 //V_MISC >= 14
8318
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8319 {
8320
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8321 new_return(27);
8322 4608 }
8323
8324
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8325 {
8326 9 section_size=writesize;
8327 9 }
8328 18 }
8329
8330
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8331 {
8332 char ebuf[80];
8333 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8334 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8335 }
8336
8337 9 new_return(0);
8338 }
8339
8340 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8341 {
8342 //these are here to bypass compiler warnings about unused arguments
8343 9 Header=Header;
8344
8345 9 dword section_id=ID_ITEMS;
8346 9 dword section_version=V_ITEMS;
8347 // dword section_size=0;
8348 9 dword section_size = 0;
8349
8350 //section id
8351
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8352 {
8353 new_return(1);
8354 }
8355
8356 //section version info
8357
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8358 {
8359 new_return(2);
8360 }
8361
8362
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8363 {
8364 new_return(3);
8365 }
8366
8367
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8368 {
8369 18 fake_pack_writing=(writecycle==0);
8370
8371 //section size
8372
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8373 {
8374 new_return(4);
8375 }
8376
8377 18 writesize=0;
8378
8379 //finally... section data
8380
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8381 {
8382 new_return(5);
8383 }
8384
8385
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8386 {
8387
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8388 {
8389 new_return(5);
8390 }
8391 4608 }
8392
8393
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8394 {
8395
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8396 {
8397 new_return(6);
8398 }
8399
8400
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8401 {
8402 new_return(7);
8403 }
8404
8405
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8406 {
8407 new_return(8);
8408 }
8409
8410
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8411 {
8412 new_return(9);
8413 }
8414
8415
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8416 {
8417 new_return(10);
8418 }
8419
8420
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8421 {
8422 new_return(11);
8423 }
8424
8425
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8426 {
8427 new_return(12);
8428 }
8429
8430
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8431 {
8432 new_return(13);
8433 }
8434
8435
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8436 {
8437 new_return(14);
8438 }
8439
8440
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8441 {
8442 new_return(14);
8443 }
8444
8445
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8446 {
8447 new_return(15);
8448 }
8449
8450
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8451 {
8452 new_return(16);
8453 }
8454
8455
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8456 {
8457 new_return(17);
8458 }
8459
8460
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8461 {
8462 new_return(18);
8463 }
8464
8465
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8466 {
8467 new_return(19);
8468 }
8469
8470
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8471 {
8472 new_return(21);
8473 }
8474
8475
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8476 {
8477 new_return(22);
8478 }
8479
8480
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8481 {
8482 new_return(23);
8483 }
8484
8485
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8486 {
8487
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8488 {
8489 new_return(24);
8490 }
8491 36864 }
8492
8493
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8494 {
8495
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8496 {
8497 new_return(25);
8498 }
8499 9216 }
8500
8501
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8502 {
8503 new_return(26);
8504 }
8505
8506
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8507 {
8508 new_return(27);
8509 }
8510
8511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8512 {
8513 new_return(28);
8514 }
8515
8516
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8517 {
8518 new_return(29);
8519 }
8520
8521
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8522 {
8523 new_return(30);
8524 }
8525
8526
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8527 {
8528 new_return(31);
8529 }
8530
8531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8532 {
8533 new_return(32);
8534 }
8535
8536
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8537 {
8538 new_return(33);
8539 }
8540
8541
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8542 {
8543 new_return(34);
8544 }
8545
8546
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8547 {
8548 new_return(35);
8549 }
8550
8551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8552 {
8553 new_return(36);
8554 }
8555
8556
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8557 {
8558 new_return(37);
8559 }
8560
8561
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8562 {
8563 new_return(38);
8564 }
8565
8566
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8567 {
8568
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8569 {
8570 new_return(39);
8571 }
8572 9216 }
8573
8574
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8575 {
8576 new_return(40);
8577 }
8578
8579
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8580 {
8581 new_return(41);
8582 }
8583
8584
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8585 {
8586 new_return(42);
8587 }
8588
8589
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8590 {
8591 new_return(43);
8592 }
8593
8594
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8595 {
8596 new_return(44);
8597 }
8598
8599
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8600 {
8601 new_return(45);
8602 }
8603
8604
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8605 {
8606 new_return(46);
8607 }
8608
8609
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8610 {
8611 new_return(47);
8612 }
8613
8614
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8615 {
8616 new_return(48);
8617 }
8618
8619
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8620 {
8621 new_return(48);
8622 }
8623
8624 //New itemdata vars -Z
8625 //! version 27
8626
8627
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8628 {
8629 new_return(51);
8630 }
8631
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8632 {
8633 new_return(52);
8634 }
8635
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8636
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8637 {
8638 new_return(53);
8639 }
8640 46080 }
8641 //version 28
8642
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8643 {
8644 new_return(54);
8645 }
8646
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8647 {
8648
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8649 {
8650 new_return(56);
8651 }
8652 9216 }
8653
8654
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8655 {
8656 new_return(57);
8657 }
8658
8659
8660
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8661 {
8662 new_return(58);
8663 }
8664
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8665 {
8666 new_return(59);
8667 }
8668
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8669 {
8670 new_return(60);
8671 }
8672
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8673 {
8674 new_return(61);
8675 }
8676
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8677 {
8678 new_return(62);
8679 }
8680
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8681 {
8682 new_return(63);
8683 }
8684
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8685 {
8686 new_return(64);
8687 }
8688
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8689 {
8690 new_return(73);
8691 }
8692
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8693 {
8694
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8695 {
8696 new_return(74);
8697 }
8698 9216 }
8699
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8700 {
8701 new_return(75);
8702 }
8703
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8704 {
8705 new_return(76);
8706 }
8707
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8708 {
8709 new_return(77);
8710 }
8711
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8712 {
8713 new_return(81);
8714 }
8715
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8716 {
8717 new_return(82);
8718 }
8719
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8720 {
8721 new_return(83);
8722 }
8723
8724
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8725 {
8726
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8727 {
8728 new_return(84);
8729 }
8730 9216 }
8731
8732 //InitD[] labels
8733
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8734 {
8735
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8736 {
8737
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8738 {
8739 new_return(85);
8740 }
8741 2396160 }
8742
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8743 {
8744
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8745 {
8746 new_return(87);
8747 }
8748 2396160 }
8749
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8750 {
8751 new_return(88);
8752 }
8753 36864 }
8754
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8755 {
8756
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8757 {
8758 new_return(89);
8759 }
8760
8761 9216 }
8762
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8763 {
8764 new_return(90);
8765 }
8766
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8767 {
8768 new_return(91);
8769 }
8770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8771
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8772 new_return(92);
8773
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_putc(itemsbuf[i].pickup_litems, f))
8774 new_return(95);
8775
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8776 new_return(96);
8777
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8778 new_return(97);
8779
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8780 return ret;
8781
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8782 new_return(98);
8783
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8784
8785
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8786 {
8787 9 section_size=writesize;
8788 9 }
8789 18 }
8790
8791
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8792 {
8793 char ebuf[80];
8794 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8795 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8796 }
8797
8798 9 new_return(0);
8799 9 }
8800
8801 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8802 {
8803 //these are here to bypass compiler warnings about unused arguments
8804 9 Header=Header;
8805
8806 9 dword section_id=ID_WEAPONS;
8807 9 dword section_version=V_WEAPONS;
8808 9 dword section_size = 0;
8809
8810 //section id
8811
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8812 {
8813 new_return(1);
8814 }
8815
8816 //section version info
8817
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8818 {
8819 new_return(2);
8820 }
8821
8822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8823 {
8824 new_return(3);
8825 }
8826
8827
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8828 {
8829 18 fake_pack_writing=(writecycle==0);
8830
8831 //section size
8832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8833 {
8834 new_return(4);
8835 }
8836
8837 18 writesize=0;
8838
8839 //finally... section data
8840
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8841 {
8842 new_return(5);
8843 }
8844
8845
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8846 {
8847
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8848 {
8849 new_return(5);
8850 }
8851 4608 }
8852
8853
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8854 {
8855
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8856 {
8857 new_return(7);
8858 }
8859
8860
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8861 {
8862 new_return(8);
8863 }
8864
8865
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8866 {
8867 new_return(9);
8868 }
8869
8870
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8871 {
8872 new_return(10);
8873 }
8874
8875
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8876 {
8877 new_return(11);
8878 }
8879
8880
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8881 {
8882 new_return(12);
8883 }
8884
8885
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8886 {
8887 new_return(12);
8888 }
8889 4608 }
8890
8891
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8892 {
8893 9 section_size=writesize;
8894 9 }
8895 18 }
8896
8897
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8898 {
8899 char ebuf[80];
8900 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8901 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8902 }
8903
8904 9 new_return(0);
8905 }
8906
8907 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8908 {
8909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8910 return qe_invalid;
8911
8912 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8913 12784 bool is_0x80_screen = j >= 0x80;
8914
8915
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8916 return qe_invalid;
8917
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8918 4404 return qe_OK;
8919 //Calculate what needs writing
8920 8380 uint32_t scr_has_flags = 0;
8921
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8922
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8923 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8924
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8925 446 scr_has_flags |= SCRHAS_ITEM;
8926
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8927 28 scr_has_flags |= SCRHAS_TWARP;
8928
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8929 {
8930
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8931
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8932
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8933 {
8934 176 scr_has_flags |= SCRHAS_TWARP;
8935 176 break;
8936 }
8937 32706 }
8938
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8939
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8940 36 scr_has_flags |= SCRHAS_SWARP;
8941
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8942 {
8943
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8944
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8945
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8946 {
8947 4270 scr_has_flags |= SCRHAS_SWARP;
8948 4270 break;
8949 }
8950 16298 }
8951
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8952 44 scr_has_flags |= SCRHAS_WARPRET;
8953
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8954 {
8955
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8956 {
8957 784 scr_has_flags |= SCRHAS_WARPRET;
8958 784 break;
8959 }
8960 30208 }
8961
8962
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8963 scr_has_flags |= SCRHAS_LAYERS;
8964
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8965 {
8966
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8967
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8968 {
8969 966 scr_has_flags |= SCRHAS_LAYERS;
8970 966 break;
8971 }
8972 44532 }
8973
8974
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8975 10 scr_has_flags |= SCRHAS_MAZE;
8976
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8977 scr_has_flags |= SCRHAS_MAZE;
8978
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8979 {
8980
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8981 {
8982 scr_has_flags |= SCRHAS_MAZE;
8983 break;
8984 }
8985 33480 }
8986
8987
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8988
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8989
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8990 2968 scr_has_flags |= SCRHAS_D_S_U;
8991
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8992 {
8993
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8994 {
8995 5212 scr_has_flags |= SCRHAS_D_S_U;
8996 5212 break;
8997 }
8998 800 }
8999
9000
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
9001
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
9002
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
9003
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
9004
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
9005
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
9006 8380 scr_has_flags |= SCRHAS_FLAGS;
9007
9008
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
9009 58 scr_has_flags |= SCRHAS_ENEMY;
9010
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
9011 {
9012
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
9013 {
9014 1014 scr_has_flags |= SCRHAS_ENEMY;
9015 1014 break;
9016 }
9017 73086 }
9018
9019
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
9020 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
9021 8380 scr_has_flags |= SCRHAS_CARRY;
9022
9023
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
9024 22 scr_has_flags |= SCRHAS_SCRIPT;
9025
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
9026 {
9027
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
9028 {
9029 scr_has_flags |= SCRHAS_SCRIPT;
9030 break;
9031 }
9032 66864 }
9033
9034
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
9035 {
9036
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
9037
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9038
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9039 {
9040 3076 scr_has_flags |= SCRHAS_SECRETS;
9041 3076 break;
9042 }
9043 680916 }
9044
9045
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9046 {
9047
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9048
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9049 {
9050 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9051 5360 break;
9052 }
9053 568532 }
9054
9055
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9056
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9057
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9058 || screen.timedwarptics || screen.screen_midi != -1
9059 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9060 8380 scr_has_flags |= SCRHAS_MISC;
9061
9062
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9063 return qe_invalid;
9064
9065 //Write stuff
9066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9067 {
9068
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9069 return qe_invalid;
9070
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9071 return qe_invalid;
9072
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9073 return qe_invalid;
9074
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9075 return qe_invalid;
9076
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9077 return qe_invalid;
9078
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9079 return qe_invalid;
9080
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9081 return qe_invalid;
9082 8380 }
9083
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9084 {
9085
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9086 return qe_invalid;
9087
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9088 return qe_invalid;
9089
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9090 return qe_invalid;
9091
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9092 return qe_invalid;
9093 446 }
9094
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9095 {
9096
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9097 return qe_invalid;
9098 4374 }
9099
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9100 {
9101
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9102 {
9103
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9104 return qe_invalid;
9105 816 }
9106
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9107 {
9108
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9109 return qe_invalid;
9110 816 }
9111
9112
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9113 {
9114
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9115 return qe_invalid;
9116 816 }
9117
9118
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9119 return qe_invalid;
9120 204 }
9121
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9122 {
9123
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9124 {
9125
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9126 return qe_invalid;
9127 17224 }
9128
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9129 {
9130
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9131 return qe_invalid;
9132 17224 }
9133
9134
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9135 {
9136
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9137 return qe_invalid;
9138 17224 }
9139
9140
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9141 return qe_invalid;
9142
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9143 return qe_invalid;
9144 4306 }
9145
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9146 {
9147
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9148 {
9149
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9150 return qe_invalid;
9151 3312 }
9152
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9153 {
9154
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9155 return qe_invalid;
9156 3312 }
9157
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9158 return qe_invalid;
9159
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9160 return qe_invalid;
9161 828 }
9162
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9163 {
9164
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9165 {
9166
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9167 return qe_invalid;
9168 5796 }
9169
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9170 {
9171
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9172 return qe_invalid;
9173 5796 }
9174
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9175 {
9176
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9177 return qe_invalid;
9178 5796 }
9179
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9180 return qe_invalid;
9181
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9182 return qe_invalid;
9183 966 }
9184
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9185 {
9186
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9187 {
9188
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9189 return qe_invalid;
9190 40 }
9191
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9192 return qe_invalid;
9193
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9194 return qe_invalid;
9195 10 }
9196
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9197 {
9198
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9199 return qe_invalid;
9200
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9201 {
9202
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9203 return qe_invalid;
9204 32720 }
9205
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9206 return qe_invalid;
9207
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9208 return qe_invalid;
9209
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9210 return qe_invalid;
9211
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9212 return qe_invalid;
9213 8180 }
9214
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9215 {
9216
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9217 return qe_invalid;
9218
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9219 return qe_invalid;
9220
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9221 return qe_invalid;
9222
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9223 return qe_invalid;
9224
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9225 return qe_invalid;
9226
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9227 return qe_invalid;
9228
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9231 return qe_invalid;
9232
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9233 return qe_invalid;
9234
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9235 return qe_invalid;
9236
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9237 return qe_invalid;
9238 1294 }
9239
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9240 {
9241
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9242 {
9243
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9244 return qe_invalid;
9245 10720 }
9246
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9247 return qe_invalid;
9248 1072 }
9249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9250 {
9251
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9252 return qe_invalid;
9253
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9254 return qe_invalid;
9255
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9256 return qe_invalid;
9257
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9258 return qe_invalid;
9259
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9260 return qe_invalid;
9261
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9262 return qe_invalid;
9263 8380 }
9264
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9265 {
9266
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9267 return qe_invalid;
9268
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9269 return qe_invalid;
9270
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9271 {
9272
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9273 return qe_invalid;
9274 176 }
9275 22 }
9276
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9277 {
9278
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9279 {
9280
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9281 return qe_invalid;
9282 393728 }
9283
9284
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9285 {
9286
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9287 return qe_invalid;
9288 393728 }
9289
9290
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9291 {
9292
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9293 return qe_invalid;
9294 393728 }
9295 3076 }
9296
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9297 {
9298
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9299 {
9300
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9301 return qe_invalid;
9302 943360 }
9303
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9304 {
9305
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9306 return qe_invalid;
9307 943360 }
9308
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9309 {
9310
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9311 return qe_invalid;
9312 943360 }
9313 5360 }
9314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9315 {
9316
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9317 return qe_invalid;
9318
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9319 return qe_invalid;
9320
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9321 return qe_invalid;
9322
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9323 return qe_invalid;
9324
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9325 return qe_invalid;
9326
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9327 return qe_invalid;
9328
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9329 return qe_invalid;
9330
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9331 return qe_invalid;
9332
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9333 return qe_invalid;
9334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9335 return qe_invalid;
9336
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9337 return qe_invalid;
9338 8380 }
9339
9340 8380 dword numffc = screen.numFFC();
9341
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9342 return qe_invalid;
9343
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9344 {
9345 245678 ffcdata const& tempffc = screen.ffcs[k];
9346
9347
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9348 return qe_invalid;
9349
9350
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9351 243364 continue;
9352
9353
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9354 return qe_invalid;
9355
9356
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9357 return qe_invalid;
9358
9359
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9360 return qe_invalid;
9361
9362
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9363 return qe_invalid;
9364
9365
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9366 return qe_invalid;
9367
9368
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9369 return qe_invalid;
9370
9371
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9372 return qe_invalid;
9373
9374
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9375 return qe_invalid;
9376
9377
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9378 return qe_invalid;
9379
9380
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9381 return qe_invalid;
9382
9383
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9384 return qe_invalid;
9385
9386
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9387 return qe_invalid;
9388
9389
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9390 return qe_invalid;
9391
9392
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9393 return qe_invalid;
9394
9395
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9396 return qe_invalid;
9397
9398
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9399 {
9400
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9401 return qe_invalid;
9402 18512 }
9403
9404
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9405 return qe_invalid;
9406 2314 }
9407
9408
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9409 return qe_invalid;
9410
9411
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9412 {
9413
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9414 return qe_invalid;
9415
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9416 return qe_invalid;
9417 6 }
9418
9419 8380 return qe_OK;
9420 12784 }
9421
9422 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9423 {
9424 9 dword section_id=ID_MAPS;
9425 9 dword section_version=V_MAPS;
9426 9 dword section_size = 0;
9427
9428 //section id
9429
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9430 {
9431 new_return(1);
9432 }
9433
9434 //section version info
9435
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9436 {
9437 new_return(2);
9438 }
9439
9440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9441 {
9442 new_return(3);
9443 }
9444
9445
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9446 {
9447 18 fake_pack_writing=(writecycle==0);
9448
9449 //section size
9450
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9451 {
9452 new_return(4);
9453 }
9454
9455 18 writesize=0;
9456
9457
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9458 {
9459 new_return(5);
9460 }
9461 18 map_autolayers.resize(map_count*6);
9462
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9463 {
9464 100 byte valid = 0;
9465
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 944 times.
950 for(int32_t j=0; j<MAPSCRS; j++)
9466 {
9467
1/2
✓ Branch 0 taken 944 times.
✗ Branch 1 not taken.
944 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9468 break;
9469 944 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9470
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 850 times.
944 if (screen.is_valid())
9471 {
9472 94 valid = 1;
9473 94 break;
9474 }
9475 850 }
9476
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9477 {
9478 new_return(6);
9479 }
9480
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9481
9482 { //per-map info
9483
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9484 {
9485 564 size_t ind = i*6+q;
9486
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(map_autolayers[ind],f))
9487 new_return(7);
9488 564 }
9489
9490
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9491 {
9492
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9493 {
9494
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9495 {
9496 new_return(8);
9497 }
9498 6016 }
9499 752 }
9500 }
9501
9502
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9503 12784 writemapscreen(f,i,j);
9504 94 }
9505
9506
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9507 {
9508 9 section_size=writesize;
9509 9 }
9510 18 }
9511
9512
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9513 {
9514 char ebuf[80];
9515 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9516 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9517 }
9518
9519 9 new_return(0);
9520 }
9521
9522 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9523 {
9524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9525 return 22;
9526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9527 return 22;
9528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9529 return 23;
9530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9531 return 34;
9532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9533 return 35;
9534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9535 return 36;
9536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9537 return 37;
9538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9539 return 38;
9540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9541 return 39;
9542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9543 return 40;
9544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9545 return 41;
9546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9547 return 42;
9548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9549 return 43;
9550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9551 return 44;
9552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9553 return 45;
9554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9555 return 46;
9556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9557 return 47;
9558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9559 return 48;
9560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9561 return 49;
9562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9563 return 50;
9564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9565 return 51;
9566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9567 return 52;
9568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9569 return 53;
9570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9571 return 69;
9572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9573 return 70;
9574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9575 return 71;
9576
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9577 return 72;
9578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9579 return 76;
9580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9581 return 77;
9582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9583 return 89;
9584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9585 return 90;
9586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_levelitems,f))
9587 return 91;
9588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9589 return 92;
9590
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9592 return 93;
9593
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9594 return 94;
9595
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9596 return 95;
9597
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9598 return 96;
9599
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9600 return 97;
9601
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9602 return 98;
9603
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9604 return 99;
9605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9606 return 100;
9607
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9608 return 101;
9609
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9610 return 102;
9611
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9612 return 103;
9613
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9614 return 104;
9615
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9616 return 105;
9617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9618 return 106;
9619
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9620 return 107;
9621
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9622 return 108;
9623
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9624 return 109;
9625
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9626 return 110;
9627
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9628 return 111;
9629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9630 return 112;
9631
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9632 return 113;
9633
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9634 return 114;
9635
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9636 return 115;
9637
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9638 return 116;
9639
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9640 return 117;
9641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9642 return 118;
9643
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9644 return 119;
9645
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9646 return 120;
9647
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9648 return 121;
9649
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9650 return 122;
9651
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9652 return 123;
9653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9654 return 124;
9655
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9656 return 125;
9657
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9658 return 126;
9659 460 return 0;
9660 460 }
9661 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9662 {
9663 //Check what needs writing
9664 258906 word combo_has_flags = 0;
9665
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9666 {
9667
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9668
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9669 {
9670 3190 combo_has_flags |= CHAS_ATTRIB;
9671 3190 break;
9672 }
9673 2052960 }
9674
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9675 460 combo_has_flags |= CHAS_TRIG;
9676
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9677 298 combo_has_flags |= CHAS_FLAG;
9678
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9679
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9680
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9681 28174 combo_has_flags |= CHAS_ANIM;
9682
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9683 6 combo_has_flags |= CHAS_SCRIPT;
9684
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9685 {
9686
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9687 {
9688 combo_has_flags |= CHAS_SCRIPT;
9689 break;
9690 }
9691 2071200 }
9692
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9693
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9694 82514 combo_has_flags |= CHAS_BASIC;
9695
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9696
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9697
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9698
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9699
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9700
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9701
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9702 10 combo_has_flags |= CHAS_LIFT;
9703
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9704
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9705
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9706
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9707
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height)
9708 258906 combo_has_flags |= CHAS_GENERAL;
9709
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9710 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9711
9712
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9713 {
9714 return 50;
9715 }
9716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9717 //Write the combo
9718
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9719 {
9720
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9721 return 6;
9722
9723
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9724 return 7;
9725
9726
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9727 return 8;
9728
9729
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9730 return 9;
9731
9732
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9733 return 15;
9734
9735
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9736 return 10;
9737 82514 }
9738
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9739 {
9740 6 p_putcstr(tmp_cmb.label, f);
9741
9742
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9743 return 26;
9744
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9745
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9746 return 27;
9747 6 }
9748
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9749 {
9750
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9751 return 11;
9752
9753
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9754 return 12;
9755
9756
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9757 return 13;
9758
9759
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9760 return 14;
9761
9762
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9763 return 16;
9764
9765
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9766 return 18;
9767
9768
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9769 return 19;
9770 28174 }
9771
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9772 {
9773
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9774
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9775 return 20;
9776
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9777
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9778 return 25;
9779
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9780
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9781 return 32;
9782 3190 }
9783
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9784 {
9785
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9786 return 21;
9787
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9788 return 33;
9789 298 }
9790
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9791 {
9792
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9793
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9794 return 34;
9795
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9796 {
9797 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9798
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9799 460 }
9800
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9801 return 35;
9802 460 }
9803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9804 {
9805
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9806 return 54;
9807
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9808 return 55;
9809
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9810 return 56;
9811
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9812 return 57;
9813
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9814 return 58;
9815
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9816 return 59;
9817
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9818 return 60;
9819
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9820 return 61;
9821
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9822 return 62;
9823
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9824 return 63;
9825
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9826 return 64;
9827
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9828 return 65;
9829
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9830 return 66;
9831
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9832 return 67;
9833
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9834 return 68;
9835
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9836 return 78;
9837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9838 return ret;
9839 258906 }
9840
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9841 {
9842
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9843 return 73;
9844
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9845 return 74;
9846
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9847 return 75;
9848
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9849 return 79;
9850
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9851 return 80;
9852
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9853 return 81;
9854
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9855 return 82;
9856
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9857 return 83;
9858
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9859 return 84;
9860
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9861 return 85;
9862
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9863 return 86;
9864
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9865 return 87;
9866
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9867 return 88;
9868
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9869 return 89;
9870
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9871 return 90;
9872
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9873 return 91;
9874
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9875 return 92;
9876
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9877 return 93;
9878
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9879 return 94;
9880
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9881 return 95;
9882
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9883 return 96;
9884
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9885 return 97;
9886 2200 }
9887
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9888 {
9889 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9890 return ret;
9891 }
9892 258906 return 0;
9893 258906 }
9894
9895 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9896 {
9897 //these are here to bypass compiler warnings about unused arguments
9898 9 version=version;
9899 9 build=build;
9900
9901 word combos_used;
9902 9 dword section_id=ID_COMBOS;
9903 9 dword section_version=V_COMBOS;
9904 // dword section_size=0;
9905 9 combos_used = count_combos()-start_combo;
9906
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9907
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9908 9 dword section_size = 0;
9909
9910 //section id
9911
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9912 {
9913 new_return(1);
9914 }
9915
9916 //section version info
9917
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9918 {
9919 new_return(2);
9920 }
9921
9922
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9923 {
9924 new_return(3);
9925 }
9926
9927
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9928 {
9929 18 fake_pack_writing=(writecycle==0);
9930
9931 //section size
9932
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9933 {
9934 new_return(4);
9935 }
9936
9937 18 writesize=0;
9938
9939 //finally... section data
9940 18 combos_used=count_combos()-start_combo;
9941
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9943
9944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9945 {
9946 new_return(5);
9947 }
9948
9949 18 size_t end_combo = start_combo+combos_used;
9950
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9951 {
9952 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9953
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9954 258906 }
9955
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9956 {
9957 9 section_size=writesize;
9958 9 }
9959 18 }
9960
9961
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9962 {
9963 char ebuf[80];
9964 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9965 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9966 }
9967
9968 9 new_return(0);
9969 9 }
9970
9971 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9972 {
9973 //these are here to bypass compiler warnings about unused arguments
9974 9 version=version;
9975 9 build=build;
9976
9977 9 dword section_id=ID_COMBOALIASES;
9978 9 dword section_version=V_COMBOALIASES;
9979 9 dword section_size=0;
9980
9981 //section id
9982
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9983 {
9984 new_return(1);
9985 }
9986
9987 //section version info
9988
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9989 {
9990 new_return(2);
9991 }
9992
9993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9994 {
9995 new_return(3);
9996 }
9997
9998
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9999 {
10000 18 fake_pack_writing=(writecycle==0);
10001
10002 //section size
10003
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10004 {
10005 new_return(4);
10006 }
10007
10008 18 writesize=0;
10009
10010 //finally... section data
10011
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10012 {
10013
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
10014 {
10015 new_return(5);
10016 }
10017
10018
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
10019 {
10020 new_return(6);
10021 }
10022
10023 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10024
10025
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
10026 {
10027 new_return(7);
10028 }
10029
10030
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
10031 {
10032 new_return(8);
10033 }
10034
10035
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10036 {
10037 new_return(9);
10038 }
10039
10040
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10041 {
10042
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10043 {
10044 new_return(10);
10045 }
10046 149596 }
10047
10048
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10049 {
10050
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10051 {
10052 new_return(11);
10053 }
10054 149596 }
10055 147456 }
10056
10057 //Combo pools!
10058 int16_t num_cpools;
10059
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10060 {
10061
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10062 {
10063 2 ++num_cpools;
10064 2 break;
10065 }
10066 147450 }
10067
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10068
10069
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10070 {
10071 new_return(12);
10072 }
10073
10074
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10075 {
10076 6 combo_pool const& pool = combo_pools[cp];
10077 6 int32_t num_combos = pool.combos.size();
10078
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10079 {
10080 new_return(13);
10081 }
10082
10083
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10084 {
10085 26 cpool_entry const& entry = pool.combos.at(q);
10086
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10087 {
10088 new_return(14);
10089 }
10090
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10091 {
10092 new_return(15);
10093 }
10094
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10095 {
10096 new_return(16);
10097 }
10098 26 }
10099 6 }
10100
10101 //Autocombos!
10102 int16_t num_cautos;
10103
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10104 {
10105
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10106 {
10107 ++num_cautos;
10108 break;
10109 }
10110 147456 }
10111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10112
10113
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10114 {
10115 new_return(17);
10116 }
10117
10118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10119 {
10120 combo_auto const& cauto = combo_autos[ca];
10121 if (!p_putc(cauto.getType(), f))
10122 {
10123 new_return(18);
10124 }
10125 if (!p_iputl(cauto.getIconDisplay(), f))
10126 {
10127 new_return(19);
10128 }
10129 if (!p_iputl(cauto.getEraseCombo(), f))
10130 {
10131 new_return(20);
10132 }
10133 if (!p_putc(cauto.getFlags(), f))
10134 {
10135 new_return(21);
10136 }
10137 if (!p_putc(cauto.getArg(), f))
10138 {
10139 new_return(22);
10140 }
10141 int32_t num_combos = cauto.combos.size();
10142 if (!p_iputl(num_combos, f))
10143 {
10144 new_return(23);
10145 }
10146
10147 for (auto q = 0; q < num_combos; ++q)
10148 {
10149 autocombo_entry const& entry = cauto.combos.at(q);
10150 if (!p_putc(entry.ctype, f))
10151 {
10152 new_return(24);
10153 }
10154 if (!p_iputl(entry.cid, f))
10155 {
10156 new_return(25);
10157 }
10158 }
10159 }
10160
10161
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10162 {
10163 9 section_size=writesize;
10164 9 }
10165 18 }
10166
10167
10168
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10169 {
10170 char ebuf[80];
10171 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10172 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10173 }
10174
10175 9 new_return(0);
10176 }
10177
10178 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10179 {
10180 //these are here to bypass compiler warnings about unused arguments
10181 9 version=version;
10182 9 build=build;
10183 9 start_cset=start_cset;
10184 9 max_csets=max_csets;
10185
10186 9 dword section_id=ID_CSETS;
10187 9 dword section_version=V_CSETS;
10188 9 int32_t palcycles = count_palcycles(&QMisc);
10189 // int32_t palcyccount = count_palcycles(&QMisc);
10190 9 dword section_size = 0;
10191
10192 //section id
10193
10194
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10195 {
10196 new_return(1);
10197 }
10198
10199 //section version info
10200
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10201 {
10202 new_return(2);
10203 }
10204
10205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10206 {
10207 new_return(3);
10208 }
10209
10210
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10211 {
10212 18 fake_pack_writing=(writecycle==0);
10213
10214 //section size
10215
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10216 {
10217 new_return(4);
10218 }
10219
10220 18 writesize=0;
10221
10222 //finally... section data
10223
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10224 {
10225 new_return(5);
10226 }
10227
10228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10229 {
10230 new_return(6);
10231 }
10232
10233
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10234 {
10235 new_return(15);
10236 }
10237
10238
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10239 {
10240
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10241 {
10242
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10243 {
10244 new_return(16);
10245 }
10246 1650 }
10247
10248
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10249 {
10250
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10251 {
10252 new_return(17);
10253 }
10254 1650 }
10255
10256
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10257 {
10258
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10259 {
10260 new_return(18);
10261 }
10262 1650 }
10263 550 }
10264
10265
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10266 {
10267 9 section_size=writesize;
10268 9 }
10269 18 }
10270
10271
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10272 {
10273 char ebuf[80];
10274 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10275 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10276 }
10277
10278 9 new_return(0);
10279 }
10280
10281 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10282 {
10283 //these are here to bypass compiler warnings about unused arguments
10284 9 version=version;
10285 9 build=build;
10286 9 start_msgstr=start_msgstr;
10287 9 max_msgstrs=max_msgstrs;
10288
10289 9 dword section_id=ID_STRINGS;
10290 9 dword section_version=V_STRINGS;
10291 9 dword section_size = 0;
10292
10293 //section id
10294
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10295 {
10296 new_return(1);
10297 }
10298
10299 //section version info
10300
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10301 {
10302 new_return(2);
10303 }
10304
10305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10306 {
10307 new_return(3);
10308 }
10309
10310
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10311 {
10312 18 fake_pack_writing=(writecycle==0);
10313
10314 //section size
10315
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10316 {
10317 new_return(4);
10318 }
10319
10320 18 writesize=0;
10321
10322 //finally... section data
10323
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10324 {
10325 return qe_invalid;
10326 }
10327
10328
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10329 {
10330 836 int32_t sz = MsgStrings[i].s.size();
10331
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10332
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10333 {
10334 return qe_invalid;
10335 }
10336
10337 836 char const* tmpstr = MsgStrings[i].s.c_str();
10338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10339 {
10340
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10341 {
10342 return qe_invalid;
10343 }
10344 836 }
10345
10346
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10347 {
10348 return qe_invalid;
10349 }
10350
10351
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10352 {
10353 return qe_invalid;
10354 }
10355
10356
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10357 {
10358 return qe_invalid;
10359 }
10360
10361
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10362 {
10363 return qe_invalid;
10364 }
10365
10366
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10367 {
10368 return qe_invalid;
10369 }
10370
10371
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10372 {
10373 return qe_invalid;
10374 }
10375
10376
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10377 {
10378 return qe_invalid;
10379 }
10380
10381
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10382 {
10383 return qe_invalid;
10384 }
10385
10386
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10387 {
10388 return qe_invalid;
10389 }
10390
10391
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10392 {
10393 return qe_invalid;
10394 }
10395
10396
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10397 {
10398 return qe_invalid;
10399 }
10400
10401
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10402 {
10403 return qe_invalid;
10404 }
10405
10406
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10407 {
10408
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10409 {
10410 return qe_invalid;
10411 }
10412 3344 }
10413
10414
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10415 {
10416 return qe_invalid;
10417 }
10418
10419
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10420 {
10421 return qe_invalid;
10422 }
10423
10424
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10425 {
10426 return qe_invalid;
10427 }
10428
10429
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10430 {
10431 return qe_invalid;
10432 }
10433
10434
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10435 {
10436 return qe_invalid;
10437 }
10438
10439
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10440 {
10441 return qe_invalid;
10442 }
10443
10444
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10445 {
10446 return qe_invalid;
10447 }
10448
10449
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10450 {
10451 return qe_invalid;
10452 }
10453
10454
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10455 {
10456 return qe_invalid;
10457 }
10458
10459
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10460 {
10461 return qe_invalid;
10462 }
10463
10464
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10465 {
10466 return qe_invalid;
10467 }
10468 836 }
10469
10470
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10471 {
10472 9 section_size=writesize;
10473 9 }
10474 18 }
10475
10476
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10477 {
10478 char ebuf[80];
10479 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10480 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10481 }
10482
10483 9 new_return(0);
10484 9 }
10485
10486 int32_t writestrings_text(PACKFILE *f)
10487 {
10488 std::map<int32_t, int32_t> msglistcache;
10489
10490 for(int32_t index = 1; index<msg_count; index++)
10491 {
10492 for(int32_t i=1; i<msg_count; i++)
10493 {
10494 if(MsgStrings[i].listpos==index)
10495 {
10496 msglistcache[index-1]=i;
10497 break;
10498 }
10499 }
10500 }
10501
10502 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10503 {
10504 fake_pack_writing=(writecycle==0);
10505 char ebuf[32];
10506
10507 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10508
10509 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10510 {
10511 return qe_invalid;
10512 }
10513
10514 for(int32_t i=1; i<msg_count; i++)
10515 {
10516 int32_t str = msglistcache[i-1];
10517
10518 if(!str)
10519 continue;
10520
10521 if(MsgStrings[str].nextstring != 0)
10522 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10523 else
10524 sprintf(ebuf,"\n\n___%d___\n", str);
10525
10526 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10527 {
10528 return qe_invalid;
10529 }
10530
10531 std::string text = MsgStrings[str].serialize();
10532 if (!pfwrite(text.c_str(), text.size(), f))
10533 {
10534 return qe_invalid;
10535 }
10536 }
10537 }
10538
10539 new_return(0);
10540 }
10541
10542 1 int32_t writestrings_tsv(PACKFILE *f)
10543 {
10544 1 std::stringstream ss;
10545
10546
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10547
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10548
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10549
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10550
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10551
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10553
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10554
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10555
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10556
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10557
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10558
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10559
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10560
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10561
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10562
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10563
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10564
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10565
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10566
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10567
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10568
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10569
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10570
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10571
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10572 };
10573
10574
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10575 {
10576
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10577
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10578 1 break;
10579
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10580 }
10581
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10582
10583 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10584
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10585
10586
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10587 {
10588 35 auto& msg = MsgStrings[i];
10589
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10590 {
10591
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10592
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10593
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10594 35 break;
10595
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10596
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10597
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10598 35 }
10599
10600
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10601
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10602 {
10603 return qe_invalid;
10604 }
10605
10606 1 new_return(0);
10607 1 }
10608
10609 std::string parse_to_legacy_msg_str_encoding(std::string const& s);
10610
10611 void parse_strings_tsv(std::string tsv)
10612 {
10613 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10614 { "message", [](auto& msg, auto& text){ msg.setFromLegacyEncoding(parse_to_legacy_msg_str_encoding(text)); } },
10615 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10616 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10617 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10618 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10619 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10620 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10621 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10622 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10623 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10624 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10625 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10626 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10627 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10628 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10629 { "margin", [&](auto& msg, auto& text){
10630 std::vector<std::string> strs;
10631 util::split(text, strs, ' ');
10632 if (strs.size() != 4)
10633 throw std::runtime_error("margin field must have 4 components");
10634 msg.margins[0] = std::stoi(strs[0]);
10635 msg.margins[1] = std::stoi(strs[1]);
10636 msg.margins[2] = std::stoi(strs[2]);
10637 msg.margins[3] = std::stoi(strs[3]);
10638 } },
10639 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10640 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10641 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10642 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10643 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10644 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10645 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10646 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10647 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10648 };
10649
10650 std::vector<std::string> rows;
10651 util::split(tsv, rows, '\n');
10652 if (rows.size())
10653 {
10654 std::string last = rows.back();
10655 util::trimstr(last);
10656 if (last.empty())
10657 rows.pop_back();
10658 }
10659 if (rows.size() <= 1)
10660 throw std::runtime_error("missing header row");
10661
10662 std::vector<std::string> columns;
10663 util::split(rows[0], columns, '\t');
10664 for (auto name : columns)
10665 {
10666 if (!fields.contains(name))
10667 throw std::runtime_error(fmt::format("invalid field: {}", name));
10668 }
10669
10670 int start_index = 1;
10671 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10672 start_index += 1;
10673
10674 int num_strings = rows.size() - start_index + 1;
10675 if (num_strings > MAXMSGS-1)
10676 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10677
10678 std::vector<MsgStr> msgs;
10679 msgs.reserve(num_strings);
10680 for (int i = start_index; i < rows.size(); i++)
10681 {
10682 std::vector<std::string> strs;
10683 util::split(rows[i], strs, '\t');
10684 if (strs.size() != columns.size())
10685 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10686
10687 int j = 0;
10688 auto& msg = msgs.emplace_back();
10689 for (auto& name : columns)
10690 {
10691 auto& fn = fields[name];
10692 try
10693 {
10694 fn(msg, strs[j++]);
10695 }
10696 catch (std::exception& ex)
10697 {
10698 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10699 }
10700 }
10701 }
10702
10703 init_msgstrings(0, msgs.size());
10704 for (int i = 0; i < msgs.size(); i++)
10705 MsgStrings[i + 1] = msgs[i];
10706 msg_count = msgs.size() + 1;
10707 msglistcache.clear();
10708 }
10709
10710 bool isblanktile(tiledata *buf, int32_t i);
10711 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10712 {
10713 //these are here to bypass compiler warnings about unused arguments
10714 9 version=version;
10715 9 build=build;
10716
10717 int32_t tiles_used;
10718 9 dword section_id=ID_TILES;
10719 9 dword section_version=V_TILES;
10720 9 al_trace("Counting tiles used\n");
10721 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10722
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10723
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10724 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10725 9 dword section_size = 0;
10726
10727 //section id
10728
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10729 {
10730 new_return(1);
10731 }
10732
10733 //section version info
10734
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10735 {
10736 new_return(2);
10737 }
10738
10739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10740 {
10741 new_return(3);
10742 }
10743
10744
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10745 {
10746 18 fake_pack_writing=(writecycle==0);
10747
10748 //section size
10749
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10750 {
10751 new_return(4);
10752 }
10753
10754 18 writesize=0;
10755
10756 //finally... section data
10757 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10758
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10759
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10760
10761
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10762 {
10763 new_return(5);
10764 }
10765
10766
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10767 {
10768
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10769 {
10770
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10771 new_return(8);
10772 365770 }
10773 else
10774 {
10775 330614 int format = newtilebuf[start_tile+i].format;
10776
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10777 {
10778 new_return(6);
10779 }
10780
10781
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10782 {
10783 byte temp_tile[128];
10784 327742 byte *di = temp_tile;
10785 327742 byte *src = newtilebuf[start_tile+i].data;
10786
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10787 {
10788 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10789 41950976 ++di;
10790 41950976 }
10791
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10792 {
10793 new_return(7);
10794 }
10795 327742 }
10796
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10797 {
10798 new_return(7);
10799 }
10800 }
10801 696384 }
10802
10803
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10804 {
10805 9 section_size=writesize;
10806 9 }
10807 18 }
10808
10809
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10810 {
10811 char ebuf[80];
10812 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10813 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10814 }
10815
10816 9 new_return(0);
10817 }
10818
10819 /* MIDI Format
10820 section_id LONG
10821 section_version WORD
10822 section_cversion WORD
10823 section_size LONG
10824 midi_flags 32 Byte ? BITFIELD[252]
10825
10826 [
10827 title 36
10828 start 4
10829 loop_start 4
10830 loop_end 4
10831 loop 2
10832 volume 2
10833 midi *
10834 ]
10835
10836 */
10837
10838 9 int32_t writemidis(PACKFILE *f)
10839 {
10840 9 dword section_id=ID_MIDIS;
10841 9 dword section_version=V_MIDIS;
10842 9 dword section_size = 0;
10843
10844 //section id
10845
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10846 {
10847 new_return(1);
10848 }
10849
10850 //section version info
10851
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10852 {
10853 new_return(2);
10854 }
10855
10856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10857 {
10858 new_return(3);
10859 }
10860
10861
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10862 {
10863 18 fake_pack_writing=(writecycle==0);
10864
10865 //section size
10866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10867 {
10868 new_return(4);
10869 }
10870
10871 18 writesize=0;
10872
10873 //finally... section data
10874
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10875 {
10876 new_return(5);
10877 }
10878
10879
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10880 {
10881
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10882 {
10883
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10884 {
10885 new_return(6);
10886 }
10887
10888
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10889 {
10890 new_return(7);
10891 }
10892
10893
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10894 {
10895 new_return(8);
10896 }
10897
10898
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10899 {
10900 new_return(9);
10901 }
10902
10903
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10904 {
10905 new_return(10);
10906 }
10907
10908
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10909 {
10910 new_return(11);
10911 }
10912
10913
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10914 {
10915 new_return(12);
10916 }
10917
10918 130 byte format = MFORMAT_MIDI;
10919
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10920 {
10921 new_return(13);
10922 }
10923
10924
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10925 130 }
10926 4536 }
10927
10928
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10929 {
10930 9 section_size=writesize;
10931 9 }
10932 18 }
10933
10934
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10935 {
10936 char ebuf[80];
10937 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10938 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10939 }
10940
10941 9 new_return(0);
10942 }
10943
10944 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10945 {
10946 9 dword section_id=ID_CHEATS;
10947 9 dword section_version=V_CHEATS;
10948 9 dword section_size = 0;
10949
10950 //section id
10951
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10952 {
10953 new_return(1);
10954 }
10955
10956 //section version info
10957
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10958 {
10959 new_return(2);
10960 }
10961
10962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10963 {
10964 new_return(3);
10965 }
10966
10967
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10968 {
10969 18 fake_pack_writing=(writecycle==0);
10970
10971 //section size
10972
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10973 {
10974 new_return(4);
10975 }
10976
10977 18 writesize=0;
10978
10979 //finally... section data
10980
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10981 {
10982 new_return(5);
10983 }
10984
10985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10986 {
10987
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10988 {
10989 new_return(6);
10990 }
10991
10992
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10993 {
10994 new_return(7);
10995 }
10996 18 }
10997
10998
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10999 {
11000 9 section_size=writesize;
11001 9 }
11002 18 }
11003
11004
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11005 {
11006 char ebuf[80];
11007 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11008 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11009 }
11010
11011 9 new_return(0);
11012 }
11013
11014 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11015 {
11016 //these are here to bypass compiler warnings about unused arguments
11017 9 Header=Header;
11018
11019 9 dword section_id=ID_GUYS;
11020 9 dword section_version=V_GUYS;
11021 9 dword section_size=0;
11022
11023 //section id
11024
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11025 {
11026 new_return(1);
11027 }
11028
11029 //section version info
11030
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11031 {
11032 new_return(2);
11033 }
11034
11035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11036 {
11037 new_return(3);
11038 }
11039
11040
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11041 {
11042 18 fake_pack_writing=(writecycle==0);
11043
11044 //section size
11045
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11046 {
11047 new_return(4);
11048 }
11049
11050 18 writesize=0;
11051
11052 //finally... section data
11053
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11054 {
11055
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11056 {
11057 new_return(5);
11058 }
11059 9216 }
11060
11061
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11062 {
11063 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11064 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11065
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11066 {
11067 new_return(6);
11068 }
11069
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11070 {
11071 new_return(7);
11072 }
11073
11074
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11075 {
11076 new_return(8);
11077 }
11078
11079
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11080 {
11081 new_return(9);
11082 }
11083
11084
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11085 {
11086 new_return(10);
11087 }
11088
11089
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11090 {
11091 new_return(11);
11092 }
11093
11094
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11095 {
11096 new_return(12);
11097 }
11098
11099
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11100 {
11101 new_return(13);
11102 }
11103
11104
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11105 {
11106 new_return(14);
11107 }
11108
11109
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11110 {
11111 new_return(15);
11112 }
11113
11114
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11115 {
11116 new_return(16);
11117 }
11118
11119
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11120 {
11121 new_return(17);
11122 }
11123
11124
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11125 {
11126 new_return(18);
11127 }
11128
11129
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11130 {
11131 new_return(19);
11132 }
11133
11134
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11135 {
11136 new_return(20);
11137 }
11138
11139
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11140 {
11141 new_return(21);
11142 }
11143
11144
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11145 {
11146 new_return(22);
11147 }
11148
11149
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11150 {
11151 new_return(23);
11152 }
11153
11154
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11155 {
11156 new_return(24);
11157 }
11158
11159
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11160 {
11161 new_return(25);
11162 }
11163
11164
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11165 {
11166 new_return(26);
11167 }
11168
11169
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11170 {
11171 new_return(27);
11172 }
11173
11174
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11175 {
11176 new_return(28);
11177 }
11178
11179
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11180 {
11181 new_return(29);
11182 }
11183
11184
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11185 {
11186 new_return(30);
11187 }
11188
11189
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11190 {
11191 new_return(31);
11192 }
11193
11194
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11195 {
11196 new_return(32);
11197 }
11198
11199
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11200 {
11201 new_return(33);
11202 }
11203
11204
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11205 {
11206 new_return(34);
11207 }
11208
11209
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11210 {
11211 new_return(35);
11212 }
11213
11214
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11215 {
11216 new_return(36);
11217 }
11218
11219
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11220 {
11221 new_return(37);
11222 }
11223
11224
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11225 {
11226 new_return(38);
11227 }
11228
11229
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11230 {
11231 new_return(39);
11232 }
11233
11234
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11235 {
11236 new_return(40);
11237 }
11238
11239
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11240 {
11241 new_return(41);
11242 }
11243
11244
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11245 {
11246 new_return(42);
11247 }
11248
11249
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11250 {
11251 new_return(43);
11252 }
11253
11254
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11255 {
11256 new_return(44);
11257 }
11258
11259
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11260 {
11261 new_return(45);
11262 }
11263
11264
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11265 {
11266
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11267 {
11268 new_return(46);
11269 }
11270 175104 }
11271
11272
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11273 {
11274 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11276 //Force SFX_HIT here.
11277
11278 2048 }
11279
11280
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11281 {
11282 new_return(47);
11283 }
11284
11285
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11286 {
11287 new_return(48);
11288 }
11289
11290
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11291 {
11292 new_return(49);
11293 }
11294
11295
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11296 {
11297 new_return(50);
11298 }
11299
11300 //New 2.6 defences
11301
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11302 {
11303
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11304 {
11305 new_return(51);
11306 }
11307 202752 }
11308
11309 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11310
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11311 {
11312 new_return(52);
11313 }
11314
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11315 {
11316 new_return(53);
11317 }
11318
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11319 {
11320 new_return(54);
11321 }
11322
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11323 {
11324 new_return(55);
11325 }
11326
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11327 {
11328 new_return(56);
11329 }
11330 // These are not fixed types, but ints, so they are safe to use here.
11331
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11332 {
11333 new_return(57);
11334 }
11335
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11336 {
11337 new_return(58);
11338 }
11339
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11340 {
11341 new_return(59);
11342 }
11343
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11344 {
11345 new_return(60);
11346 }
11347
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11348 {
11349 new_return(61);
11350 }
11351
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11352 {
11353 new_return(62);
11354 }
11355
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11356 {
11357 new_return(63);
11358 }
11359
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11360 {
11361 new_return(64);
11362 }
11363
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11364 {
11365 new_return(65);
11366 }
11367
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11368 {
11369 new_return(66);
11370 }
11371
11372
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11373 {
11374
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11375 {
11376 new_return(67);
11377 }
11378 92160 }
11379
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11380 {
11381 new_return(68);
11382 }
11383 //misc 16->31
11384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11385 {
11386 new_return(69);
11387 }
11388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11389 {
11390 new_return(70);
11391 }
11392
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11393 {
11394 new_return(71);
11395 }
11396
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11397 {
11398 new_return(72);
11399 }
11400
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11401 {
11402 new_return(73);
11403 }
11404
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11405 {
11406 new_return(74);
11407 }
11408
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11409 {
11410 new_return(75);
11411 }
11412
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11413 {
11414 new_return(76);
11415 }
11416
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11417 {
11418 new_return(77);
11419 }
11420
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11421 {
11422 new_return(78);
11423 }
11424
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11425 {
11426 new_return(79);
11427 }
11428
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11429 {
11430 new_return(80);
11431 }
11432
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11433 {
11434 new_return(81);
11435 }
11436
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11437 {
11438 new_return(82);
11439 }
11440
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11441 {
11442 new_return(83);
11443 }
11444
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11445 {
11446 new_return(84);
11447 }
11448
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11449 {
11450 new_return(85);
11451 }
11452
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11453 {
11454
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11455 {
11456 new_return(86);
11457 }
11458 294912 }
11459
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11460 {
11461
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11462 {
11463 new_return(87);
11464 }
11465 294912 }
11466
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11467 {
11468 new_return(88);
11469 }
11470
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11471 {
11472
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11473 {
11474 new_return(89);
11475 }
11476 73728 }
11477
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11478 {
11479
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11480 {
11481 new_return(90);
11482 }
11483 18432 }
11484
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11485 {
11486 new_return(91);
11487 }
11488 //somehow forgot these in the older builds -Z
11489
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11490 {
11491 new_return(92);
11492 }
11493
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11494 {
11495 new_return(93);
11496 }
11497
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11498 {
11499 new_return(94);
11500 }
11501
11502 //Enemy Editor InitD[] labels
11503
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11504 {
11505
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11506 {
11507
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11508 {
11509 new_return(95);
11510 }
11511 4792320 }
11512 73728 }
11513
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11514 new_return(99);
11515
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11516 new_return(100);
11517
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11518 new_return(101);
11519
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11520 new_return(102);
11521
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11522 new_return(103);
11523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11524 return ret;
11525 9216 }
11526
11527
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11528 {
11529 9 section_size=writesize;
11530 9 }
11531 18 }
11532
11533
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11534 {
11535 char ebuf[80];
11536 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11537 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11538 }
11539
11540 9 new_return(0);
11541 9 }
11542
11543 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11544 {
11545 //these are here to bypass compiler warnings about unused arguments
11546 9 Header=Header;
11547
11548 9 dword section_id=ID_HEROSPRITES;
11549 9 dword section_version=V_HEROSPRITES;
11550 9 dword section_size=0;
11551
11552 //section id
11553
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11554 {
11555 new_return(1);
11556 }
11557
11558 //section version info
11559
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11560 {
11561 new_return(2);
11562 }
11563
11564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11565 {
11566 new_return(3);
11567 }
11568
11569
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11570 {
11571 18 fake_pack_writing=(writecycle==0);
11572
11573 //section size
11574
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11575 {
11576 new_return(4);
11577 }
11578
11579 18 writesize=0;
11580
11581 //finally... section data
11582
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11583 {
11584
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11585 {
11586 new_return(5);
11587 }
11588
11589
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11590 {
11591 new_return(5);
11592 }
11593
11594
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11595 {
11596 new_return(5);
11597 }
11598 72 }
11599
11600
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11601 {
11602
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11603 {
11604 new_return(6);
11605 }
11606
11607
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11608 {
11609 new_return(6);
11610 }
11611
11612
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11613 {
11614 new_return(6);
11615 }
11616 72 }
11617
11618
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11619 {
11620
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11621 {
11622 new_return(7);
11623 }
11624
11625
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11626 {
11627 new_return(7);
11628 }
11629
11630
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11631 {
11632 new_return(7);
11633 }
11634 72 }
11635
11636
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11637 {
11638
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11639 {
11640 new_return(8);
11641 }
11642
11643
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11644 {
11645 new_return(8);
11646 }
11647
11648
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11649 {
11650 new_return(8);
11651 }
11652 72 }
11653
11654
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11655 {
11656
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11657 {
11658 new_return(8);
11659 }
11660
11661
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11662 {
11663 new_return(8);
11664 }
11665
11666
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11667 {
11668 new_return(8);
11669 }
11670 72 }
11671
11672
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11673 {
11674
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11675 {
11676 new_return(9);
11677 }
11678
11679
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11680 {
11681 new_return(9);
11682 }
11683
11684
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11685 {
11686 new_return(9);
11687 }
11688 72 }
11689
11690
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11691 {
11692
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11693 {
11694 new_return(10);
11695 }
11696
11697
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11698 {
11699 new_return(10);
11700 }
11701
11702
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11703 {
11704 new_return(10);
11705 }
11706 72 }
11707
11708
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11709 {
11710 new_return(11);
11711 }
11712
11713
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11714 {
11715 new_return(11);
11716 }
11717
11718
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11719 {
11720 new_return(11);
11721 }
11722
11723
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11724 {
11725
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11726 {
11727
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11728 {
11729 new_return(12);
11730 }
11731
11732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11733 {
11734 new_return(12);
11735 }
11736
11737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11738 {
11739 new_return(12);
11740 }
11741 108 }
11742 36 }
11743
11744
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11745 {
11746
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11747 {
11748 new_return(13);
11749 }
11750
11751
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11752 {
11753 new_return(13);
11754 }
11755
11756
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11757 {
11758 new_return(13);
11759 }
11760 72 }
11761
11762
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11763 {
11764
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11765 {
11766 new_return(13);
11767 }
11768
11769
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11770 {
11771 new_return(13);
11772 }
11773
11774
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11775 {
11776 new_return(13);
11777 }
11778 72 }
11779
11780
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11781 {
11782 new_return(14);
11783 }
11784
11785 //{ V_HEROSPRITES >= 7
11786
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11787 {
11788
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11789 new_return(15);
11790
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11791 new_return(15);
11792
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11793 new_return(15);
11794 72 }
11795
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11796 {
11797
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11798 new_return(15);
11799
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11800 new_return(15);
11801
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11802 new_return(15);
11803 72 }
11804
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11805 {
11806
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11807 new_return(15);
11808
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11809 new_return(15);
11810
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11811 new_return(15);
11812 72 }
11813
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11814 {
11815
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11816 new_return(15);
11817
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11818 new_return(15);
11819
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11820 new_return(15);
11821 72 }
11822
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11823 {
11824
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11825 new_return(15);
11826
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11827 new_return(15);
11828
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11829 new_return(15);
11830 72 }
11831
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11832 {
11833
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11834 new_return(15);
11835
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11836 new_return(15);
11837
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11838 new_return(15);
11839 72 }
11840
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11841 {
11842
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11843 new_return(15);
11844
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11845 new_return(15);
11846
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11847 new_return(15);
11848 72 }
11849
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11850 {
11851
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11852 new_return(15);
11853
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11854 new_return(15);
11855
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11856 new_return(15);
11857 72 }
11858
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11859 {
11860
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11861 new_return(15);
11862
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11863 new_return(15);
11864
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11865 new_return(15);
11866
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11867 new_return(15);
11868 72 }
11869
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11870 {
11871
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11872 new_return(15);
11873
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11874 new_return(15);
11875
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11876 new_return(15);
11877 72 }
11878
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11879 {
11880
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11881 new_return(15);
11882
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11883 new_return(15);
11884
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11885 new_return(15);
11886 72 }
11887
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11888 {
11889
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11890 new_return(15);
11891
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11892 new_return(15);
11893
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11894 new_return(15);
11895 72 }
11896
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11897 {
11898
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11899 new_return(15);
11900
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11901 new_return(15);
11902
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11903 new_return(15);
11904 72 }
11905
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11906 {
11907
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11908 new_return(15);
11909
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11910 new_return(15);
11911
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11912 new_return(15);
11913 72 }
11914
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11915 {
11916
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11917 new_return(15);
11918
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11919 new_return(15);
11920
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11921 new_return(15);
11922 72 }
11923
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11924 {
11925
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11926 new_return(15);
11927
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11928 new_return(15);
11929
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11930 new_return(15);
11931 72 }
11932
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11933 {
11934
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11935 new_return(15);
11936
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11937 new_return(15);
11938
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11939 new_return(15);
11940 72 }
11941
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11942 {
11943
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11944 new_return(15);
11945
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11946 new_return(15);
11947
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11948 new_return(15);
11949 72 }
11950
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11951 {
11952
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11953 new_return(15);
11954
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11955 new_return(15);
11956
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11957 new_return(15);
11958 72 }
11959
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11960 {
11961
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11962 new_return(15);
11963
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11964 new_return(15);
11965
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11966 new_return(15);
11967 72 }
11968
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11969 {
11970
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11971 new_return(15);
11972
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11973 new_return(15);
11974
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11975 new_return(15);
11976 72 }
11977
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11978 {
11979
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11980 new_return(15);
11981
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11982 new_return(15);
11983
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11984 new_return(15);
11985 72 }
11986
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11987 {
11988
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11989 new_return(15);
11990
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11991 new_return(15);
11992
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11993 new_return(15);
11994 72 }
11995
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11996 {
11997
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11998 new_return(15);
11999
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12000 new_return(15);
12001
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12002 new_return(15);
12003 54 }
12004
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12005 {
12006
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
12007 new_return(16);
12008
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12009 new_return(16);
12010
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12011 new_return(16);
12012 72 }
12013
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12014 {
12015
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12016 new_return(17);
12017
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12018 new_return(17);
12019
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12020 new_return(17);
12021 72 }
12022
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12023 {
12024
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12025 new_return(17);
12026
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12027 new_return(17);
12028
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12029 new_return(17);
12030 72 }
12031
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12032 {
12033
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12034 new_return(17);
12035
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12036 new_return(17);
12037
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12038 new_return(17);
12039 72 }
12040
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12041 {
12042
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12043 new_return(18);
12044
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12045 new_return(18);
12046
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12047 new_return(18);
12048 72 }
12049
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12050 {
12051
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12052 new_return(19);
12053 72 }
12054
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12055 {
12056
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12057 new_return(20);
12058
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12059 new_return(20);
12060
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12061 new_return(20);
12062 54 }
12063
12064
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12065 {
12066 new_return(21);
12067 }
12068
12069
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12070 {
12071 new_return(21);
12072 }
12073
12074
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12075 {
12076 new_return(21);
12077 }
12078
12079
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12080 {
12081
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12082 new_return(22);
12083
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12084 new_return(22);
12085
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12086 new_return(22);
12087 72 }
12088
12089
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12090 {
12091
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12092 {
12093 new_return(23);
12094 }
12095
12096
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12097 {
12098 new_return(23);
12099 }
12100
12101
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12102 {
12103 new_return(23);
12104 }
12105 72 }
12106
12107
12108
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12109 {
12110
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12111 new_return(15);
12112 2628 }
12113 //}
12114
12115
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12116 {
12117 9 section_size=writesize;
12118 9 }
12119 18 }
12120
12121 //More data will come here
12122
12123
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12124 {
12125 char ebuf[80];
12126 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12127 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12128 }
12129
12130 9 new_return(0);
12131 }
12132
12133 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12134 {
12135 9 dword section_id=ID_SUBSCREEN;
12136 9 dword section_version=V_SUBSCREEN;
12137 9 dword section_size=0;
12138
12139 //section id
12140
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12141 {
12142 new_return(1);
12143 }
12144
12145 //section version info
12146
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12147 {
12148 new_return(2);
12149 }
12150
12151
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12152 {
12153 new_return(3);
12154 }
12155
12156
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12157 {
12158 18 fake_pack_writing=(writecycle==0);
12159
12160 //section size
12161
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12162 {
12163 new_return(4);
12164 }
12165
12166 18 writesize=0;
12167
12168 18 byte sz = subscreens_active.size();
12169
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12170 new_return(5);
12171
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12172 {
12173 86 int32_t ret = subscreens_active[i].write(f);
12174 86 fake_pack_writing=(writecycle==0);
12175
12176
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12177 new_return(ret);
12178 86 }
12179
12180 18 sz = subscreens_passive.size();
12181
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12182 new_return(5);
12183
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12184 {
12185 64 int32_t ret = subscreens_passive[i].write(f);
12186 64 fake_pack_writing=(writecycle==0);
12187
12188
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12189 new_return(ret);
12190 64 }
12191
12192 18 sz = subscreens_overlay.size();
12193
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12194 new_return(5);
12195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12196 {
12197 int32_t ret = subscreens_overlay[i].write(f);
12198 fake_pack_writing=(writecycle==0);
12199
12200 if(ret!=0)
12201 new_return(ret);
12202 }
12203
12204
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12205 {
12206 9 section_size=writesize;
12207 9 }
12208 18 }
12209
12210
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12211 {
12212 char ebuf[80];
12213 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12214 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12215 }
12216
12217 9 new_return(0);
12218 9 }
12219
12220 extern script_data *ffscripts[NUMSCRIPTFFC];
12221 extern script_data *itemscripts[NUMSCRIPTITEM];
12222 extern script_data *guyscripts[NUMSCRIPTGUYS];
12223 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12224 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12225 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12226 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12227 extern script_data *playerscripts[NUMSCRIPTHERO];
12228 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12229 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12230 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12231 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12232 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12233
12234 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12235 {
12236
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12237 3 return writeffscript_old(f, Header);
12238
12239 6 dword section_id = ID_FFSCRIPT;
12240 6 dword section_version = V_FFSCRIPT;
12241 6 dword section_size = 0;
12242 6 dword zasmmeta_version = METADATA_V;
12243 6 byte numscripts = 0;
12244 6 numscripts = numscripts; //to avoid unused variables warnings
12245
12246 //section id
12247
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12248 {
12249 new_return(1);
12250 }
12251
12252 //section version info
12253
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12254 {
12255 new_return(2);
12256 }
12257
12258
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12259 {
12260 new_return(3);
12261 }
12262
12263
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12264 {
12265 new_return(4);
12266 }
12267
12268
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12269 {
12270 12 fake_pack_writing=(writecycle==0);
12271
12272 //section size
12273
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12274 {
12275 new_return(5);
12276 }
12277
12278 12 writesize=0;
12279
12280 12 write_quest_zasm(f);
12281
12282
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12283 {
12284 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12285
12286
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12287 {
12288 new_return(ret);
12289 }
12290 6144 }
12291
12292
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12293 {
12294 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12295
12296
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12297 {
12298 new_return(ret);
12299 }
12300 3072 }
12301
12302
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12303 {
12304 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12305
12306
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12307 {
12308 new_return(ret);
12309 }
12310 3072 }
12311
12312
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12313
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12314 {
12315 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12316
12317
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12318 {
12319 new_return(ret);
12320 }
12321 3072 }
12322
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12323
12324
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12325 {
12326 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12327
12328
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12329 {
12330 new_return(ret);
12331 }
12332 3072 }
12333
12334
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12335 {
12336 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12337
12338
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12339 {
12340 new_return(ret);
12341 }
12342 96 }
12343
12344
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12345 {
12346 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12347
12348
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12349 {
12350 new_return(ret);
12351 }
12352 60 }
12353
12354
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12355 {
12356 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12357
12358
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12359 {
12360 new_return(ret);
12361 }
12362 3072 }
12363
12364
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12365 {
12366 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12367
12368
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12369 {
12370 new_return(ret);
12371 }
12372 3072 }
12373
12374
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12375 {
12376 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12377
12378
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12379 {
12380 new_return(ret);
12381 }
12382 3072 }
12383
12384
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12385 {
12386 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12387
12388
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12389 {
12390 new_return(ret);
12391 }
12392 3072 }
12393
12394
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12395 {
12396 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12397
12398
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12399 {
12400 new_return(ret);
12401 }
12402 6144 }
12403
12404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12405 {
12406 new_return(2000);
12407 }
12408
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12409 {
12410 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12411
12412
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12413 {
12414 new_return(ret);
12415 }
12416 6144 }
12417
12418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12419 {
12420 new_return(2001);
12421 }
12422
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12423 {
12424 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12425
12426
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12427 {
12428 new_return(ret);
12429 }
12430 3072 }
12431
12432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12433 {
12434 new_return(2001);
12435 }
12436
12437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12438 {
12439 new_return(2002);
12440 }
12441
12442 12 word numffcbindings=0;
12443
12444
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12445 {
12446
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12447 {
12448 158 numffcbindings++;
12449 158 }
12450 6132 }
12451
12452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12453 {
12454 new_return(2003);
12455 }
12456
12457
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12458 {
12459
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12460 {
12461
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12462 {
12463 new_return(2004);
12464 }
12465
12466
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12467 {
12468 new_return(2005);
12469 }
12470
12471
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12472 {
12473 new_return(2006);
12474 }
12475 158 }
12476 6132 }
12477
12478 12 word numglobalbindings=0;
12479
12480
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12481 {
12482
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12483 {
12484 22 numglobalbindings++;
12485 22 }
12486 96 }
12487
12488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12489 {
12490 new_return(2007);
12491 }
12492
12493
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12494 {
12495
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12496 {
12497
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12498 {
12499 new_return(2008);
12500 }
12501
12502
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12503 {
12504 new_return(2009);
12505 }
12506
12507
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12508 {
12509 new_return(2010);
12510 }
12511 22 }
12512 96 }
12513
12514 12 word numitembindings=0;
12515
12516
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12517 {
12518
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12519 {
12520 26 numitembindings++;
12521 26 }
12522 3060 }
12523
12524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12525 {
12526 new_return(2011);
12527 }
12528
12529
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12530 {
12531
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12532 {
12533
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12534 {
12535 new_return(2012);
12536 }
12537
12538
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12539 {
12540 new_return(2013);
12541 }
12542
12543
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12544 {
12545 new_return(2014);
12546 }
12547 26 }
12548 3060 }
12549
12550 //new script types
12551 //npc scripts
12552 12 word numnpcbindings=0;
12553
12554
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12555 {
12556
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12557 {
12558 numnpcbindings++;
12559 }
12560 3060 }
12561
12562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12563 {
12564 new_return(2015);
12565 }
12566
12567
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12568 {
12569
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12570 {
12571 if(!p_iputw(it->first,f))
12572 {
12573 new_return(2016);
12574 }
12575
12576 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12577 {
12578 new_return(2017);
12579 }
12580
12581 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12582 {
12583 new_return(2018);
12584 }
12585 }
12586 3060 }
12587
12588 //lweapon
12589
12590 12 word numlwpnbindings=0;
12591
12592
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12593 {
12594
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12595 {
12596 2 numlwpnbindings++;
12597 2 }
12598 3060 }
12599
12600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12601 {
12602 new_return(2019);
12603 }
12604
12605
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12606 {
12607
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12608 {
12609
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12610 {
12611 new_return(2020);
12612 }
12613
12614
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12615 {
12616 new_return(2021);
12617 }
12618
12619
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12620 {
12621 new_return(2022);
12622 }
12623 2 }
12624 3060 }
12625
12626 //////
12627
12628 //eweapon
12629
12630
12631 12 word numewpnbindings=0;
12632
12633
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12634 {
12635
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12636 {
12637 numewpnbindings++;
12638 }
12639 3060 }
12640
12641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12642 {
12643 new_return(2023);
12644 }
12645
12646
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12647 {
12648
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12649 {
12650 if(!p_iputw(it->first,f))
12651 {
12652 new_return(2024);
12653 }
12654
12655 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12656 {
12657 new_return(2025);
12658 }
12659
12660 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12661 {
12662 new_return(2026);
12663 }
12664 }
12665 3060 }
12666
12667 //player scripts
12668 12 word numherobindings=0;
12669
12670
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12671 {
12672
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12673 {
12674 numherobindings++;
12675 }
12676 48 }
12677
12678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12679 {
12680 new_return(2027);
12681 }
12682
12683
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12684 {
12685
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12686 {
12687 if(!p_iputw(it->first,f))
12688 {
12689 new_return(2028);
12690 }
12691
12692 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12693 {
12694 new_return(2029);
12695 }
12696
12697 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12698 {
12699 new_return(2030);
12700 }
12701 }
12702 48 }
12703
12704 //dmap scripts
12705 12 word numdmapbindings=0;
12706
12707
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12708 {
12709
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12710 {
12711 10 numdmapbindings++;
12712 10 }
12713 3060 }
12714
12715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12716 {
12717 new_return(2031);
12718 }
12719
12720
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12721 {
12722
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12723 {
12724
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12725 {
12726 new_return(2032);
12727 }
12728
12729
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12730 {
12731 new_return(2033);
12732 }
12733
12734
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12735 {
12736 new_return(2034);
12737 }
12738 10 }
12739 3060 }
12740
12741 //screen scripts
12742 12 word numscreenbindings=0;
12743
12744
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12745 {
12746
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12747 {
12748 4 numscreenbindings++;
12749 4 }
12750 3060 }
12751
12752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12753 {
12754 new_return(2035);
12755 }
12756
12757
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12758 {
12759
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12760 {
12761
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12762 {
12763 new_return(2036);
12764 }
12765
12766
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12767 {
12768 new_return(2037);
12769 }
12770
12771
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12772 {
12773 new_return(2038);
12774 }
12775 4 }
12776 3060 }
12777 //item sprite scripts
12778 12 word numitemspritebindings=0;
12779
12780
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12781 {
12782
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12783 {
12784 numitemspritebindings++;
12785 }
12786 3060 }
12787
12788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12789 {
12790 new_return(2039);
12791 }
12792
12793
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12794 {
12795
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12796 {
12797 if(!p_iputw(it->first,f))
12798 {
12799 new_return(2040);
12800 }
12801
12802 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12803 {
12804 new_return(2041);
12805 }
12806
12807 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12808 {
12809 new_return(2042);
12810 }
12811 }
12812 3060 }
12813
12814 //combo scripts
12815 12 word numcombobindings=0;
12816
12817
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12818 {
12819
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12820 {
12821 numcombobindings++;
12822 }
12823 6132 }
12824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12825 {
12826 new_return(2043);
12827 }
12828
12829
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12830 {
12831
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12832 {
12833 if(!p_iputw(it->first,f))
12834 {
12835 new_return(2044);
12836 }
12837
12838 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12839 {
12840 new_return(2045);
12841 }
12842
12843 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12844 {
12845 new_return(2046);
12846 }
12847 }
12848 6132 }
12849 //subscreen scripts
12850 12 word numgenericbindings=0;
12851
12852
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12853 {
12854
2/2
✓ Branch 0 taken 6092 times.
✓ Branch 1 taken 40 times.
6132 if(it->second.scriptname != "")
12855 {
12856 40 numgenericbindings++;
12857 40 }
12858 6132 }
12859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12860 {
12861 new_return(2043);
12862 }
12863
12864
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12865 {
12866
2/2
✓ Branch 0 taken 6092 times.
✓ Branch 1 taken 40 times.
6132 if(it->second.scriptname != "")
12867 {
12868
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_iputw(it->first,f))
12869 {
12870 new_return(2044);
12871 }
12872
12873
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12874 {
12875 new_return(2045);
12876 }
12877
12878
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12879 {
12880 new_return(2046);
12881 }
12882 40 }
12883 6132 }
12884
12885 //generic scripts
12886 12 word numsubscreenbindings=0;
12887
12888
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12889 {
12890
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12891 {
12892 numsubscreenbindings++;
12893 }
12894 3060 }
12895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12896 {
12897 new_return(2047);
12898 }
12899
12900
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12901 {
12902
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12903 {
12904 if(!p_iputw(it->first,f))
12905 {
12906 new_return(2048);
12907 }
12908
12909 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12910 {
12911 new_return(2049);
12912 }
12913
12914 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12915 {
12916 new_return(2050);
12917 }
12918 }
12919 3060 }
12920
12921
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12922 {
12923 6 section_size=writesize;
12924 6 }
12925 12 }
12926
12927
12928
12929
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12930 {
12931 char ebuf[80];
12932 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12933 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12934 }
12935
12936 6 new_return(0);
12937 //return 0; //this is just here to stomp the compiler from whining.
12938 //the irony is that it causes an "unreachable code" warning.
12939 9 }
12940
12941 12 int32_t write_quest_zasm(PACKFILE *f)
12942 {
12943 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12944
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12945 {
12946 if(!p_iputl(0,f))
12947 new_return(1);
12948
12949 return 0;
12950 }
12951
12952 12 auto& zasm = zasm_scripts[0]->zasm;
12953 12 size_t num_commands = zasm.size();
12954
12955
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12956 new_return(1);
12957
12958
2/2
✓ Branch 0 taken 345632 times.
✓ Branch 1 taken 12 times.
345644 for(int32_t j=0; j<num_commands; j++)
12959 {
12960 345632 auto& zas = zasm[j];
12961
12962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 345632 times.
345632 if(zas.command==0xFFFF)
12963 continue;
12964 else
12965 {
12966
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputw(zas.command,f))
12967 new_return(2);
12968
12969
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg1,f))
12970 new_return(3);
12971
12972
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg2,f))
12973 new_return(4);
12974
12975
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg3,f))
12976 new_return(5);
12977
12978 345632 uint32_t sz = 0;
12979
2/2
✓ Branch 0 taken 344678 times.
✓ Branch 1 taken 954 times.
345632 if(zas.strptr)
12980 954 sz = zas.strptr->size();
12981
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(sz,f))
12982 new_return(6);
12983
2/2
✓ Branch 0 taken 344690 times.
✓ Branch 1 taken 942 times.
345632 if(sz)
12984 {
12985 942 auto& str = *zas.strptr;
12986
2/2
✓ Branch 0 taken 19592 times.
✓ Branch 1 taken 942 times.
20534 for(size_t q = 0; q < sz; ++q)
12987 {
12988
1/2
✓ Branch 0 taken 19592 times.
✗ Branch 1 not taken.
19592 if(!p_putc(str[q],f))
12989 new_return(7);
12990 19592 }
12991 942 }
12992 345632 sz = 0;
12993
2/2
✓ Branch 0 taken 345432 times.
✓ Branch 1 taken 200 times.
345632 if(zas.vecptr)
12994 200 sz = zas.vecptr->size();
12995
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(sz,f))
12996 new_return(8);
12997
2/2
✓ Branch 0 taken 345432 times.
✓ Branch 1 taken 200 times.
345632 if(sz) //vector found
12998 {
12999 200 auto& vec = *zas.vecptr;
13000
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 200 times.
1000 for(size_t q = 0; q < sz; ++q)
13001 {
13002
1/2
✓ Branch 0 taken 800 times.
✗ Branch 1 not taken.
800 if(!p_iputl(vec[q],f))
13003 new_return(9);
13004 800 }
13005 200 }
13006 }
13007 345632 }
13008 12 return 0;
13009 12 }
13010
13011 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
13012 {
13013
2/2
✓ Branch 0 taken 45988 times.
✓ Branch 1 taken 248 times.
46236 if (!script->valid())
13014 {
13015
1/2
✓ Branch 0 taken 45988 times.
✗ Branch 1 not taken.
45988 if (!p_putc(0, f))
13016 new_return(-1);
13017 45988 return 0;
13018 }
13019
13020
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if (!p_putc(1, f))
13021 new_return(-1);
13022
13023 248 zasm_meta const& tmeta = script->meta;
13024
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.zasm_v,f))
13025 new_return(1);
13026
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.meta_v,f))
13027 new_return(2);
13028
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.ffscript_v,f))
13029 new_return(3);
13030
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putc((int)tmeta.script_type,f))
13031 new_return(4);
13032
13033
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(int32_t q = 0; q < 8; ++q)
13034 {
13035
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.run_idens[q],f))
13036 new_return(5);
13037 1984 }
13038
13039
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(int32_t q = 0; q < 8; ++q)
13040
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putc(tmeta.run_types[q],f))
13041 new_return(6);
13042
13043
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putc(tmeta.flags,f))
13044 new_return(7);
13045
13046
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v1,f))
13047 new_return(8);
13048
13049
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v2,f))
13050 new_return(9);
13051
13052
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v3,f))
13053 new_return(10);
13054
13055
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v4,f))
13056 new_return(11);
13057
13058
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putcstr(tmeta.script_name,f))
13059 new_return(12);
13060
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putcstr(tmeta.author,f))
13061 new_return(13);
13062
2/2
✓ Branch 0 taken 2480 times.
✓ Branch 1 taken 248 times.
2728 for(auto q = 0; q < 10; ++q)
13063 {
13064
1/2
✓ Branch 0 taken 2480 times.
✗ Branch 1 not taken.
2480 if(!p_putcstr(tmeta.attributes[q],f))
13065 new_return(14);
13066
1/2
✓ Branch 0 taken 2480 times.
✗ Branch 1 not taken.
2480 if(!p_putwstr(tmeta.attributes_help[q],f))
13067 new_return(15);
13068 2480 }
13069
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13070 {
13071
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.attribytes[q],f))
13072 new_return(16);
13073
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.attribytes_help[q],f))
13074 new_return(17);
13075 1984 }
13076
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13077 {
13078
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.attrishorts[q],f))
13079 new_return(18);
13080
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13081 new_return(19);
13082 1984 }
13083
2/2
✓ Branch 0 taken 3968 times.
✓ Branch 1 taken 248 times.
4216 for(auto q = 0; q < 16; ++q)
13084 {
13085
1/2
✓ Branch 0 taken 3968 times.
✗ Branch 1 not taken.
3968 if(!p_putcstr(tmeta.usrflags[q],f))
13086 new_return(20);
13087
1/2
✓ Branch 0 taken 3968 times.
✗ Branch 1 not taken.
3968 if(!p_putwstr(tmeta.usrflags_help[q],f))
13088 new_return(21);
13089 3968 }
13090
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13091 {
13092
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.initd[q],f))
13093 new_return(22);
13094
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.initd_help[q],f))
13095 new_return(23);
13096 1984 }
13097
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13098 {
13099
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putc(tmeta.initd_type[q],f))
13100 new_return(24);
13101 1984 }
13102
13103
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputl(script->pc, f))
13104 new_return(25);
13105
13106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 248 times.
248 if(!p_iputl(script->end_pc, f))
13107 new_return(26);
13108
13109 248 return 0;
13110 46236 }
13111
13112
13113 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13114 {
13115 3 dword section_id = ID_FFSCRIPT;
13116 3 dword section_version = 26;
13117 3 dword section_cversion = 1;
13118 3 dword section_size = 0;
13119 3 dword zasmmeta_version = 5;
13120 3 byte numscripts = 0;
13121 3 numscripts = numscripts; //to avoid unused variables warnings
13122
13123 //section id
13124
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13125 {
13126 new_return(1);
13127 }
13128
13129 //section version info
13130
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13131 {
13132 new_return(2);
13133 }
13134
13135
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13136 {
13137 new_return(3);
13138 }
13139
13140
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13141 {
13142 new_return(4);
13143 }
13144
13145
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13146 {
13147 6 fake_pack_writing=(writecycle==0);
13148
13149 //section size
13150
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13151 {
13152 new_return(5);
13153 }
13154
13155 6 writesize=0;
13156
13157
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13158 {
13159 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13160 3072 fake_pack_writing=(writecycle==0);
13161
13162
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13163 {
13164 new_return(ret);
13165 }
13166 3072 }
13167
13168
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13169 {
13170 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13171 1536 fake_pack_writing=(writecycle==0);
13172
13173
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13174 {
13175 new_return(ret);
13176 }
13177 1536 }
13178
13179
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13180 {
13181 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13182 1536 fake_pack_writing=(writecycle==0);
13183
13184
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13185 {
13186 new_return(ret);
13187 }
13188 1536 }
13189
13190
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13191
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13192 {
13193 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13194 1536 fake_pack_writing=(writecycle==0);
13195
13196
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13197 {
13198 new_return(ret);
13199 }
13200 1536 }
13201
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13202
13203
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13204 {
13205 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13206 1536 fake_pack_writing=(writecycle==0);
13207
13208
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13209 {
13210 new_return(ret);
13211 }
13212 1536 }
13213
13214
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13215 {
13216 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13217 48 fake_pack_writing=(writecycle==0);
13218
13219
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13220 {
13221 new_return(ret);
13222 }
13223 48 }
13224
13225
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13226 {
13227 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13228 30 fake_pack_writing=(writecycle==0);
13229
13230
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13231 {
13232 new_return(ret);
13233 }
13234 30 }
13235
13236
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13237 {
13238 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13239 1536 fake_pack_writing=(writecycle==0);
13240
13241
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13242 {
13243 new_return(ret);
13244 }
13245 1536 }
13246
13247
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13248 {
13249 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13250 1536 fake_pack_writing=(writecycle==0);
13251
13252
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13253 {
13254 new_return(ret);
13255 }
13256 1536 }
13257
13258
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13259 {
13260 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13261 1536 fake_pack_writing=(writecycle==0);
13262
13263
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13264 {
13265 new_return(ret);
13266 }
13267 1536 }
13268
13269
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13270 {
13271 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13272 1536 fake_pack_writing=(writecycle==0);
13273
13274
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13275 {
13276 new_return(ret);
13277 }
13278 1536 }
13279
13280
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13281 {
13282 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13283 3072 fake_pack_writing=(writecycle==0);
13284
13285
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13286 {
13287 new_return(ret);
13288 }
13289 3072 }
13290
13291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13292 {
13293 new_return(2000);
13294 }
13295
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13296 {
13297 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13298 3072 fake_pack_writing=(writecycle==0);
13299
13300
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13301 {
13302 new_return(ret);
13303 }
13304 3072 }
13305
13306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13307 {
13308 new_return(2001);
13309 }
13310
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13311 {
13312 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13313 1536 fake_pack_writing=(writecycle==0);
13314
13315
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13316 {
13317 new_return(ret);
13318 }
13319 1536 }
13320
13321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13322 {
13323 new_return(2001);
13324 }
13325
13326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13327 {
13328 new_return(2002);
13329 }
13330
13331 6 word numffcbindings=0;
13332
13333
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13334 {
13335
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13336 {
13337 206 numffcbindings++;
13338 206 }
13339 3066 }
13340
13341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13342 {
13343 new_return(2003);
13344 }
13345
13346
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13347 {
13348
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13349 {
13350
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13351 {
13352 new_return(2004);
13353 }
13354
13355
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13356 {
13357 new_return(2005);
13358 }
13359
13360
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13361 {
13362 new_return(2006);
13363 }
13364 206 }
13365 3066 }
13366
13367 6 word numglobalbindings=0;
13368
13369
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13370 {
13371
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13372 {
13373 18 numglobalbindings++;
13374 18 }
13375 48 }
13376
13377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13378 {
13379 new_return(2007);
13380 }
13381
13382
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13383 {
13384
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13385 {
13386
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13387 {
13388 new_return(2008);
13389 }
13390
13391
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13392 {
13393 new_return(2009);
13394 }
13395
13396
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13397 {
13398 new_return(2010);
13399 }
13400 18 }
13401 48 }
13402
13403 6 word numitembindings=0;
13404
13405
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13406 {
13407
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13408 {
13409 18 numitembindings++;
13410 18 }
13411 1530 }
13412
13413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13414 {
13415 new_return(2011);
13416 }
13417
13418
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13419 {
13420
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13421 {
13422
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13423 {
13424 new_return(2012);
13425 }
13426
13427
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13428 {
13429 new_return(2013);
13430 }
13431
13432
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13433 {
13434 new_return(2014);
13435 }
13436 18 }
13437 1530 }
13438
13439 //new script types
13440 //npc scripts
13441 6 word numnpcbindings=0;
13442
13443
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13444 {
13445
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13446 {
13447 numnpcbindings++;
13448 }
13449 1530 }
13450
13451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13452 {
13453 new_return(2015);
13454 }
13455
13456
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13457 {
13458
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13459 {
13460 if(!p_iputw(it->first,f))
13461 {
13462 new_return(2016);
13463 }
13464
13465 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13466 {
13467 new_return(2017);
13468 }
13469
13470 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13471 {
13472 new_return(2018);
13473 }
13474 }
13475 1530 }
13476
13477 //lweapon
13478
13479 6 word numlwpnbindings=0;
13480
13481
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13482 {
13483
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13484 {
13485 numlwpnbindings++;
13486 }
13487 1530 }
13488
13489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13490 {
13491 new_return(2019);
13492 }
13493
13494
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13495 {
13496
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13497 {
13498 if(!p_iputw(it->first,f))
13499 {
13500 new_return(2020);
13501 }
13502
13503 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13504 {
13505 new_return(2021);
13506 }
13507
13508 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13509 {
13510 new_return(2022);
13511 }
13512 }
13513 1530 }
13514
13515 //////
13516
13517 //eweapon
13518
13519
13520 6 word numewpnbindings=0;
13521
13522
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13523 {
13524
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13525 {
13526 numewpnbindings++;
13527 }
13528 1530 }
13529
13530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13531 {
13532 new_return(2023);
13533 }
13534
13535
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13536 {
13537
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13538 {
13539 if(!p_iputw(it->first,f))
13540 {
13541 new_return(2024);
13542 }
13543
13544 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13545 {
13546 new_return(2025);
13547 }
13548
13549 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13550 {
13551 new_return(2026);
13552 }
13553 }
13554 1530 }
13555
13556 //player scripts
13557 6 word numherobindings=0;
13558
13559
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13560 {
13561
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13562 {
13563 2 numherobindings++;
13564 2 }
13565 24 }
13566
13567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13568 {
13569 new_return(2027);
13570 }
13571
13572
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13573 {
13574
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13575 {
13576
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13577 {
13578 new_return(2028);
13579 }
13580
13581
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13582 {
13583 new_return(2029);
13584 }
13585
13586
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13587 {
13588 new_return(2030);
13589 }
13590 2 }
13591 24 }
13592
13593 //dmap scripts
13594 6 word numdmapbindings=0;
13595
13596
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13597 {
13598
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13599 {
13600 numdmapbindings++;
13601 }
13602 1530 }
13603
13604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13605 {
13606 new_return(2031);
13607 }
13608
13609
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13610 {
13611
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13612 {
13613 if(!p_iputw(it->first,f))
13614 {
13615 new_return(2032);
13616 }
13617
13618 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13619 {
13620 new_return(2033);
13621 }
13622
13623 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13624 {
13625 new_return(2034);
13626 }
13627 }
13628 1530 }
13629
13630 //screen scripts
13631 6 word numscreenbindings=0;
13632
13633
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13634 {
13635
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13636 {
13637 14 numscreenbindings++;
13638 14 }
13639 1530 }
13640
13641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13642 {
13643 new_return(2035);
13644 }
13645
13646
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13647 {
13648
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13649 {
13650
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13651 {
13652 new_return(2036);
13653 }
13654
13655
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13656 {
13657 new_return(2037);
13658 }
13659
13660
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13661 {
13662 new_return(2038);
13663 }
13664 14 }
13665 1530 }
13666 //item sprite scripts
13667 6 word numitemspritebindings=0;
13668
13669
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13670 {
13671
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13672 {
13673 numitemspritebindings++;
13674 }
13675 1530 }
13676
13677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13678 {
13679 new_return(2039);
13680 }
13681
13682
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13683 {
13684
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13685 {
13686 if(!p_iputw(it->first,f))
13687 {
13688 new_return(2040);
13689 }
13690
13691 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13692 {
13693 new_return(2041);
13694 }
13695
13696 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13697 {
13698 new_return(2042);
13699 }
13700 }
13701 1530 }
13702
13703 //combo scripts
13704 6 word numcombobindings=0;
13705
13706
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13707 {
13708
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13709 {
13710 numcombobindings++;
13711 }
13712 3066 }
13713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13714 {
13715 new_return(2043);
13716 }
13717
13718
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13719 {
13720
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13721 {
13722 if(!p_iputw(it->first,f))
13723 {
13724 new_return(2044);
13725 }
13726
13727 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13728 {
13729 new_return(2045);
13730 }
13731
13732 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13733 {
13734 new_return(2046);
13735 }
13736 }
13737 3066 }
13738 //subscreen scripts
13739 6 word numgenericbindings=0;
13740
13741
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13742 {
13743
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13744 {
13745 numgenericbindings++;
13746 }
13747 3066 }
13748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13749 {
13750 new_return(2043);
13751 }
13752
13753
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13754 {
13755
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13756 {
13757 if(!p_iputw(it->first,f))
13758 {
13759 new_return(2044);
13760 }
13761
13762 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13763 {
13764 new_return(2045);
13765 }
13766
13767 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13768 {
13769 new_return(2046);
13770 }
13771 }
13772 3066 }
13773
13774 //generic scripts
13775 6 word numsubscreenbindings=0;
13776
13777
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13778 {
13779
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13780 {
13781 numsubscreenbindings++;
13782 }
13783 1530 }
13784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13785 {
13786 new_return(2047);
13787 }
13788
13789
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13790 {
13791
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13792 {
13793 if(!p_iputw(it->first,f))
13794 {
13795 new_return(2048);
13796 }
13797
13798 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13799 {
13800 new_return(2049);
13801 }
13802
13803 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13804 {
13805 new_return(2050);
13806 }
13807 }
13808 1530 }
13809
13810
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13811 {
13812 3 section_size=writesize;
13813 3 }
13814 6 }
13815
13816
13817
13818
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13819 {
13820 char ebuf[80];
13821 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13822 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13823 }
13824
13825 3 new_return(0);
13826 //return 0; //this is just here to stomp the compiler from whining.
13827 //the irony is that it causes an "unreachable code" warning.
13828 3 }
13829
13830 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13831 {
13832 //these are here to bypass compiler warnings about unused arguments
13833 23118 Header=Header;
13834 23118 i=i;
13835
13836
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13837
13838
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13839 {
13840 new_return(6);
13841 }
13842
13843 //Metadata
13844 23118 zasm_meta const& tmeta = script->meta;
13845
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13846 {
13847 new_return(7);
13848 }
13849
13850
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13851 {
13852 new_return(8);
13853 }
13854
13855
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13856 {
13857 new_return(9);
13858 }
13859
13860
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13861 {
13862 new_return(10);
13863 }
13864
13865
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13866 {
13867
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13868 new_return(11);
13869 184944 }
13870
13871
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13872 {
13873
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13874 {
13875 new_return(12);
13876 }
13877 184944 }
13878
13879
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13880 {
13881 new_return(13);
13882 }
13883
13884
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13885 {
13886 new_return(14);
13887 }
13888
13889
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13890 {
13891 new_return(15);
13892 }
13893
13894
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13895 {
13896 new_return(16);
13897 }
13898
13899
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13900 {
13901 new_return(17);
13902 }
13903
13904
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13905 new_return(18);
13906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13907 new_return(19);
13908
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13909 {
13910
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13911 new_return(27);
13912
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13913 new_return(28);
13914 231180 }
13915
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13916 {
13917
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13918 new_return(29);
13919
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13920 new_return(30);
13921 184944 }
13922
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13923 {
13924
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13925 new_return(31);
13926
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13927 new_return(32);
13928 184944 }
13929
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13930 {
13931
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13932 new_return(33);
13933
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13934 new_return(34);
13935 369888 }
13936
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13937 {
13938
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13939 new_return(35);
13940
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13941 new_return(36);
13942 184944 }
13943
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13944 {
13945
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13946 new_return(37);
13947 184944 }
13948
13949
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13950 {
13951 2056888 auto& zas = script->zasm_script->zasm[j];
13952
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13953 {
13954 new_return(20);
13955 }
13956
13957
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13958 {
13959 11830 break;
13960 }
13961 else
13962 {
13963
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13964 {
13965 new_return(21);
13966 }
13967
13968
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13969 {
13970 new_return(22);
13971 }
13972
13973
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13974 {
13975 new_return(23);
13976 }
13977
13978 2045058 uint32_t sz = 0;
13979
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13980 2340 sz = zas.strptr->size();
13981
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13982 {
13983 new_return(23);
13984 }
13985
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13986 {
13987 2340 auto& str = *zas.strptr;
13988
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13989 {
13990
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13991 {
13992 new_return(24);
13993 }
13994 214720 }
13995 2340 }
13996 2045058 sz = 0;
13997
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13998 22 sz = zas.vecptr->size();
13999
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
14000 {
14001 new_return(25);
14002 }
14003
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
14004 {
14005 22 auto& vec = *zas.vecptr;
14006
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
14007 {
14008
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
14009 {
14010 new_return(26);
14011 }
14012 352 }
14013 22 }
14014 }
14015 2045058 }
14016
14017 23118 new_return(0);
14018 }
14019
14020 extern SAMPLE customsfxdata[WAV_COUNT];
14021 extern uint8_t customsfxflag[WAV_COUNT>>3];
14022
14023 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
14024 {
14025 //these are here to bypass compiler warnings about unused arguments
14026 9 Header=Header;
14027
14028 9 dword section_id=ID_SFX;
14029 9 dword section_version=V_SFX;
14030 9 dword section_size=0;
14031
14032 //section id
14033
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14034 {
14035 new_return(1);
14036 }
14037
14038 //section version info
14039
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14040 {
14041 new_return(2);
14042 }
14043
14044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14045 {
14046 new_return(3);
14047 }
14048
14049
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14050 {
14051 18 fake_pack_writing=(writecycle==0);
14052
14053 //section size
14054
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14055 {
14056 new_return(4);
14057 }
14058
14059 18 writesize=0;
14060
14061
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14062 {
14063
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14064 {
14065 new_return(5);
14066 }
14067 576 }
14068
14069
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14070 {
14071
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14072 3330 continue;
14073
14074
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14075 {
14076 new_return(5);
14077 }
14078 1260 }
14079
14080
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14081 {
14082
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14083 3330 continue;
14084
14085
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14086 {
14087 new_return(5);
14088 }
14089
14090
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14091 {
14092 new_return(6);
14093 }
14094
14095
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14096 {
14097 new_return(7);
14098 }
14099
14100
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14101 {
14102 new_return(8);
14103 }
14104
14105
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14106 {
14107 new_return(9);
14108 }
14109
14110
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14111 {
14112 new_return(10);
14113 }
14114
14115
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14116 {
14117 new_return(11);
14118 }
14119
14120
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14121 {
14122 new_return(12);
14123 }
14124
14125 //de-endianfy the data
14126 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14127
14128
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14129 {
14130
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14131 {
14132 new_return(13);
14133 }
14134 28596352 }
14135 1260 }
14136
14137
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14138 {
14139 9 section_size=writesize;
14140 9 }
14141 18 }
14142
14143
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14144 {
14145 char ebuf[80];
14146 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14147 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14148 }
14149
14150 9 new_return(0);
14151 }
14152
14153 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14154 {
14155 9 dword section_id=ID_INITDATA;
14156 9 dword section_version=V_INITDATA;
14157 9 dword section_size = 0;
14158
14159 9 zinit.last_map=Map.getCurrMap();
14160 9 zinit.last_screen=Map.getCurrScr();
14161 9 zinit.normalize();
14162
14163 //section id
14164
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14165 {
14166 new_return(1);
14167 }
14168
14169 //section version info
14170
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14171 {
14172 new_return(2);
14173 }
14174
14175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14176 {
14177 new_return(3);
14178 }
14179
14180 //TODO
14181
14182
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14183 {
14184 18 fake_pack_writing=(writecycle==0);
14185
14186 //section size
14187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14188 new_return(4);
14189
14190 18 writesize=0;
14191
14192
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14193
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14194 new_return(5);
14195
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14196 {
14197
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(zinit.litems[q], f))
14198 new_return(6);
14199 9216 }
14200
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14201 new_return(10);
14202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14203 new_return(11);
14204
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14205
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14206 new_return(12);
14207
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14208
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14209 new_return(13);
14210
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14211 new_return(14);
14212
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14213 new_return(15);
14214
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14215 new_return(16);
14216
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14217 new_return(17);
14218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14219 new_return(18);
14220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14221 new_return(19);
14222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14223 new_return(20);
14224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14225 new_return(21);
14226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14227 new_return(22);
14228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14229 new_return(23);
14230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14231 new_return(24);
14232
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14233 new_return(25);
14234
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14235 new_return(26);
14236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14237 new_return(27);
14238
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14239 new_return(28);
14240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14241 new_return(29);
14242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14243 new_return(30);
14244
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14245 new_return(31);
14246
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14247 new_return(32);
14248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14249 new_return(33);
14250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14251 new_return(34);
14252
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14253 new_return(35);
14254
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14255 new_return(36);
14256
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14257 new_return(37);
14258
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14259 new_return(38);
14260
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14261 new_return(39);
14262
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14263 new_return(40);
14264
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14265 new_return(41);
14266
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14267 new_return(42);
14268
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14269 new_return(43);
14270
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14271 new_return(44);
14272
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14273 new_return(45);
14274
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14275 new_return(46);
14276
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14277 new_return(47);
14278
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14279 new_return(48);
14280
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14281 new_return(49);
14282
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14283 new_return(50);
14284
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14285 new_return(51);
14286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14287 new_return(52);
14288
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14289 new_return(53);
14290
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14291 new_return(54);
14292
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14293 new_return(55);
14294
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14295 new_return(56);
14296
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14297 new_return(57);
14298
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14299 new_return(58);
14300
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14301 new_return(59);
14302
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14303 new_return(60);
14304
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14305 new_return(61);
14306
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14307 new_return(62);
14308
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14309 new_return(63);
14310
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14311 new_return(64);
14312
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14313 new_return(65);
14314
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14315 new_return(66);
14316
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14317 new_return(67);
14318
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14319 new_return(68);
14320
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14321 new_return(69);
14322
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14323 new_return(70);
14324
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14325 new_return(71);
14326
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14327 new_return(72);
14328
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14329 new_return(73);
14330
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14331 new_return(74);
14332
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14333 new_return(75);
14334
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14335
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14336 new_return(76);
14337
14338
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14339 {
14340 9 section_size=writesize;
14341 9 }
14342 18 }
14343
14344
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14345 {
14346 char ebuf[80];
14347 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14348 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14349 }
14350
14351 9 new_return(0);
14352 }
14353
14354 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14355 {
14356 //these are here to bypass compiler warnings about unused arguments
14357 9 Header=Header;
14358
14359 9 dword section_id=ID_ITEMDROPSETS;
14360 9 dword section_version=V_ITEMDROPSETS;
14361 // dword section_size=0;
14362 9 dword section_size = 0;
14363 9 word num_item_drop_sets=count_item_drop_sets();
14364
14365 //section id
14366
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14367 {
14368 new_return(1);
14369 }
14370
14371 //section version info
14372
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14373 {
14374 new_return(2);
14375 }
14376
14377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14378 {
14379 new_return(3);
14380 }
14381
14382
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14383 {
14384 18 fake_pack_writing=(writecycle==0);
14385
14386 //section size
14387
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14388 {
14389 new_return(4);
14390 }
14391
14392 18 writesize=0;
14393
14394 //finally... section data
14395
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14396 {
14397 new_return(5);
14398 }
14399
14400
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14401 {
14402
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14403 {
14404 new_return(6);
14405 }
14406
14407
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14408 {
14409
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14410 {
14411 new_return(7);
14412 }
14413 2360 }
14414
14415
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14416 {
14417
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14418 {
14419 new_return(8);
14420 }
14421 2596 }
14422 236 }
14423
14424
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14425 {
14426 9 section_size=writesize;
14427 9 }
14428 18 }
14429
14430
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14431 {
14432 char ebuf[80];
14433 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14434 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14435 }
14436
14437 9 new_return(0);
14438 }
14439
14440 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14441 {
14442 9 dword section_id=ID_FAVORITES;
14443 9 dword section_version=V_FAVORITES;
14444 9 dword section_size = 0;
14445
14446 //section id
14447
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14448 {
14449 new_return(1);
14450 }
14451
14452 //section version info
14453
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14454 {
14455 new_return(2);
14456 }
14457
14458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14459 {
14460 new_return(3);
14461 }
14462
14463
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14464 {
14465 18 fake_pack_writing=(writecycle==0);
14466
14467 //section size
14468
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14469 new_return(4);
14470
14471 18 writesize=0;
14472
14473
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14474 new_return(16);
14475
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14476 new_return(17);
14477
14478 18 word favcmb_cnt = 0;
14479
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14480
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14481 {
14482 14 favcmb_cnt = q+1;
14483 14 break;
14484 }
14485
14486
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14487 new_return(5);
14488
14489
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14490 {
14491
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14492 new_return(6);
14493
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14494 new_return(7);
14495 460 }
14496
14497
14498 18 word max_combo_cols = MAX_COMBO_COLS;
14499
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14500 new_return(9);
14501
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14502 {
14503
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14504 new_return(10);
14505
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14506 new_return(11);
14507
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14508 new_return(12);
14509 72 }
14510 18 word max_mappages = MAX_MAPPAGE_BTNS;
14511
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14512 new_return(13);
14513
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14514 {
14515
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14516 new_return(14);
14517
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14518 new_return(15);
14519 162 }
14520
14521
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14522 {
14523 9 section_size=writesize;
14524 9 }
14525 18 }
14526
14527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14528 {
14529 char ebuf[80];
14530 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14531 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14532 }
14533
14534 9 new_return(0);
14535 }
14536
14537 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14538 {
14539
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14540 9 reset_combo_animations();
14541 9 reset_combo_animations2();
14542 9 strcpy(header.id_str,QH_NEWIDSTR);
14543 9 header.zelda_version = ZELDA_VERSION;
14544 9 header.internal = INTERNAL_VERSION;
14545 9 header.data_flags[ZQ_TILES] = true;
14546 9 header.data_flags[ZQ_CHEATS2] = 1;
14547 9 header.build=VERSION_BUILD;
14548
14549
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14550 {
14551 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14552 2268 }
14553
14554 char zinfofilename[2048];
14555 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14556
14557 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14558 9 box_out("Saving Quest...");
14559 9 box_eol();
14560 9 box_eol();
14561
14562
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14563
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14564
14565
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14566 return 1;
14567
14568
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14569
14570
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14571 return 2;
14572
14573
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14574
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14575
14576
14577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14578 {
14579 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14580
14581 box_out("Writing ZInfo...");
14582 if(inf)
14583 {
14584 if(writezinfo(inf,ZI)!=0)
14585 return 2;
14586
14587 pack_fclose(inf);
14588 box_out("okay.");
14589 }
14590 else box_out(" ...file failure");
14591 box_eol();
14592 }
14593 else
14594 {
14595
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14596
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14597 return 2;
14598
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14599
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14600 }
14601
14602
14603
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14604
14605
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14606 return 3;
14607
14608
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14609
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14610
14611
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14612
14613
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14614 return 4;
14615
14616
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14617
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14618
14619
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14620
14621
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14622 return 5;
14623
14624
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14625
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14626
14627
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14628
14629
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14630 return 6;
14631
14632
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14633
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14634
14635
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14636
14637
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14638 return 7;
14639
14640
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14642
14643
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14644
14645
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14646 return 8;
14647
14648
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14650
14651
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14652
14653
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14654 return 9;
14655
14656
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14657
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14658
14659
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14660
14661
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14662 return 10;
14663
14664
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14666
14667
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14668
14669
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14670 return 11;
14671
14672
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14673
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14674
14675
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14676
14677
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14678 return 12;
14679
14680
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14681
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14682
14683
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14684
14685
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14686 return 13;
14687
14688
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14690
14691
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14692
14693
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14694 return 14;
14695
14696
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14698
14699
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14700
14701
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14702 return 15;
14703
14704
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14705
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14706
14707
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14708
14709
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14710 return 16;
14711
14712
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14713
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14714
14715
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14716
14717
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14718 return 17;
14719
14720
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14721
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14722
14723
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14724
14725
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14726 return 18;
14727
14728
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14730
14731
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14732
14733
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14734 return 19;
14735
14736
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14737
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14738
14739
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14740
14741
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14742 return 20;
14743
14744
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14745
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14746
14747
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14748
14749
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14750 return 21;
14751
14752
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14753
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14754
14755
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14756
14757
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14758 return 22;
14759
14760
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14761
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14762
14763
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14764
14765
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14766 return 23;
14767
14768
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14769
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14770
14771
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14772
14773
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14774 return 24;
14775
14776
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14777
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14778
14779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14780
14781
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14782 return 25;
14783
14784
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14785
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14786
14787
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14788
14789
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14790 return 26;
14791
14792
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14793
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14794
14795
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14796
14797
14798
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14799 {
14800 char const* kfname = filename;
14801 char keyfilename[2048]={0};
14802 zprint2("Writing key files for '%s'\n", kfname);
14803
14804 char temp_pw[QSTPWD_LEN] = {0};
14805 uint ind = 0;
14806 for(char const* ext : {"key","zpwd","zcheat"})
14807 {
14808 replace_extension(keyfilename, kfname, ext, 2047);
14809 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14810 char msg[80] = {0};
14811 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14812 msg[78]=13;
14813 msg[79]=10;
14814 pfwrite(msg, 80, fp);
14815 p_iputw(header.zelda_version,fp);
14816 p_putc(header.build,fp);
14817 char const* pwd = header.password;
14818 if(ind == 2) //.zcheat, hashed pwd
14819 {
14820 char hashmap = 'Z';
14821 hashmap += 'Q';
14822 hashmap += 'U';
14823 hashmap += 'E';
14824 hashmap += 'S';
14825 hashmap += 'T';
14826 for ( int q = 0; q < QSTPWD_LEN; ++q )
14827 {
14828 temp_pw[q] = header.password[q];
14829 temp_pw[q] += hashmap;
14830 }
14831 pwd = temp_pw;
14832 }
14833 pfwrite(pwd, strlen(pwd), fp);
14834 pack_fclose(fp);
14835 ++ind;
14836 }
14837 }
14838
14839 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14840 9 std::error_code ec;
14841
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14843 {
14844 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14845 return ec.value();
14846 }
14847
14848
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14849
14850 #ifdef __EMSCRIPTEN__
14851 em_sync_fs();
14852 #endif
14853
14854 9 return 0;
14855 9 }
14856
14857 // #ifdef _WIN32
14858 // static std::time_t to_time_t(FILETIME const& ft) {
14859 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14860 // t -= 116444736000000000ull;
14861 // t /= 10000000u;
14862 // return static_cast<std::time_t>(t);
14863 // }
14864 // #else
14865 // #endif
14866 template<typename TP>
14867 6 static std::time_t to_time_t(TP tp) {
14868 using namespace std::chrono;
14869 6 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14870 6 return system_clock::to_time_t(sctp);
14871 }
14872
14873 6 std::string get_time_last_modified_string(std::string path)
14874 {
14875
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto write_time = fs::last_write_time(path);
14876 // TODO: C++20 but not supported yet.
14877 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14878 6 std::time_t tt = to_time_t(write_time);
14879 6 std::tm *gmt = std::gmtime(&tt);
14880 6 std::stringstream buffer;
14881
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 buffer << std::put_time(gmt, "%Y-%m-%d");
14882
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string formattedFileTime = buffer.str();
14883 6 return formattedFileTime;
14884
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 }
14885
14886 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14887 {
14888 // Always backup quest if it was last saved in a different version of the editor,
14889 // or if this a new file and is overwritting another qst file.
14890
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14891 {
14892 6 std::string backup_name;
14893
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string last_mod = get_time_last_modified_string(filename);
14894
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (strlen(header.zelda_version_string) > 0)
14895 {
14896
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14897 6 }
14898 else
14899 {
14900 backup_name = fmt::format("{}", last_mod);
14901 }
14902
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
6 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14903
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 fs::path backup_path = fs::path("backups") / backup_fname;
14904
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!fs::exists(backup_path))
14905 {
14906
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::create_directories(fs::path("backups"));
14907
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if (fs::copy_file(filename, backup_path))
14908 {
14909
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
6 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14910 6 }
14911 else
14912 {
14913 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14914 }
14915 6 }
14916 6 }
14917
14918 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14919 9 fake_pack_writing = false;
14920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14921 {
14922 box_out("-- Error saving quest file! --");
14923 box_end(true);
14924 }
14925 9 else box_end(false);
14926 9 return ret;
14927 }
14928
14929 9 int32_t save_quest(const char *filename, bool timed_save)
14930 {
14931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14932
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14933 char ext1[5];
14934 9 ext1[0]=0;
14935
14936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14937 {
14938 sprintf(ext1, "qt");
14939 }
14940 else
14941 {
14942 9 sprintf(ext1, "qb");
14943 }
14944
14945
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14946 {
14947 char backupname[2048];
14948 char backupname2[2048];
14949 char ext[12];
14950
14951 for(int32_t i=retention-1; i>0; --i)
14952 {
14953 sprintf(ext, "%s%d", ext1, i-1);
14954 replace_extension(backupname, filepath, ext, 2047);
14955
14956 if(exists(backupname))
14957 {
14958 sprintf(ext, "%s%d", ext1, i);
14959 replace_extension(backupname2, filepath, ext, 2047);
14960
14961 if(exists(backupname2))
14962 {
14963 remove(backupname2);
14964 }
14965
14966 rename(backupname, backupname2);
14967 }
14968 }
14969
14970 //don't do this if we're not saving to the same name -DD
14971 if(!timed_save && !strcmp(filepath, filename))
14972 {
14973 sprintf(ext, "%s%d", ext1, 0);
14974 replace_extension(backupname, filepath, ext, 2047);
14975 rename(filepath, backupname);
14976 }
14977 }
14978
14979 int32_t ret;
14980 9 ret = save_unencoded_quest(filename, compress, filename);
14981
14982 9 return ret;
14983 }
14984
14985 8 void center_zq_class_dialogs()
14986 {
14987 8 jwin_center_dialog(pwd_dlg);
14988 8 }
14989
14990 void zmap::prv_secrets(bool high16only)
14991 {
14992 mapscr *s = &prvscr;
14993 mapscr *t = prvlayers;
14994 int32_t ft=0;
14995
14996 for(int32_t i=0; i<176; i++)
14997 {
14998 if(!high16only)
14999 {
15000 for(int32_t j=-1; j<6; j++)
15001 {
15002 int32_t newflag = -1;
15003
15004 for(int32_t iter=0; iter<2; ++iter)
15005 {
15006 if(!t[j].valid)
15007 continue;
15008
15009 int32_t checkflag=combobuf[t[j].data[i]].flag;
15010
15011 if(iter==1)
15012 {
15013 checkflag=t[j].sflag[i];
15014 }
15015
15016 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15017 if (ft != -1)
15018 {
15019 if(j==-1)
15020 {
15021 s->data[i] = s->secretcombo[ft];
15022 s->cset[i] = s->secretcset[ft];
15023 newflag = s->secretflag[ft];
15024 }
15025 else
15026 {
15027 t[j].data[i] = t[j].secretcombo[ft];
15028 t[j].cset[i] = t[j].secretcset[ft];
15029 newflag = t[j].secretflag[ft];
15030 }
15031 }
15032 }
15033
15034 if(newflag >-1)
15035 {
15036 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15037 }
15038 }
15039 }
15040
15041 //if(true)
15042 //{
15043 int32_t newflag = -1;
15044
15045 for(int32_t iter=0; iter<2; ++iter)
15046 {
15047 int32_t checkflag=combobuf[s->data[i]].flag;
15048
15049 if(iter==1)
15050 {
15051 checkflag=s->sflag[i];
15052 }
15053
15054 if((checkflag > 15)&&(checkflag < 32))
15055 {
15056 s->data[i] = s->secretcombo[(checkflag)-16+4];
15057 s->cset[i] = s->secretcset[(checkflag)-16+4];
15058 newflag = s->secretflag[(checkflag)-16+4];
15059 // putit = true;
15060 }
15061 }
15062
15063 if(newflag >-1) s->sflag[i] = newflag;
15064
15065 for(int32_t j=0; j<6; j++)
15066 {
15067 if(!t[j].valid) continue;
15068
15069 int32_t newflag2 = -1;
15070
15071 for(int32_t iter=0; iter<2; ++iter)
15072 {
15073 int32_t checkflag=combobuf[t[j].data[i]].flag;
15074
15075 if(iter==1)
15076 {
15077 checkflag=t[j].sflag[i];
15078 }
15079
15080 if((checkflag > 15)&&(checkflag < 32))
15081 {
15082 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15083 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15084 newflag2 = t[j].secretflag[(checkflag)-16+4];
15085 }
15086 }
15087
15088 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15089 }
15090 }
15091
15092 //FFCs
15093 word num_ffcs = s->numFFC();
15094 for(word i=0; i<num_ffcs; ++i)
15095 {
15096 if(!high16only)
15097 {
15098 for(int32_t iter=0; iter<1; ++iter)
15099 {
15100 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15101
15102 if(iter==1)
15103 {
15104 checkflag=s->sflag[i];
15105 }
15106
15107 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15108 if (ft != -1)
15109 {
15110 s->ffcs[i].data = s->secretcombo[ft];
15111 s->ffcs[i].cset = s->secretcset[ft];
15112 }
15113 }
15114 }
15115
15116 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15117 {
15118 for(int32_t iter=0; iter<1; ++iter)
15119 {
15120 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15121
15122 if(iter==1)
15123 {
15124 // FFCs can't have flags! Yet...
15125 }
15126
15127 if((checkflag > 15)&&(checkflag < 32))
15128 {
15129 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15130 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15131 }
15132 }
15133 }
15134 }
15135 }
15136